claudish 7.53.0 → 7.54.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 +1140 -464
- 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.54.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();
|
|
@@ -34819,9 +35447,9 @@ var init_antigravity2 = __esm(() => {
|
|
|
34819
35447
|
});
|
|
34820
35448
|
|
|
34821
35449
|
// src/auth/quota/sources/codex.ts
|
|
34822
|
-
import { existsSync as
|
|
34823
|
-
import { homedir as
|
|
34824
|
-
import { join as
|
|
35450
|
+
import { existsSync as existsSync15, readFileSync as readFileSync13 } from "fs";
|
|
35451
|
+
import { homedir as homedir18 } from "os";
|
|
35452
|
+
import { join as join18 } from "path";
|
|
34825
35453
|
function formatWindowMinutes(minutes) {
|
|
34826
35454
|
if (!Number.isFinite(minutes) || minutes <= 0)
|
|
34827
35455
|
return "";
|
|
@@ -34835,7 +35463,7 @@ function formatWindowMinutes(minutes) {
|
|
|
34835
35463
|
return `${hours}h${minutes % 60}m`;
|
|
34836
35464
|
}
|
|
34837
35465
|
function credentialsPath() {
|
|
34838
|
-
return
|
|
35466
|
+
return join18(homedir18(), ".claudish", "codex-oauth.json");
|
|
34839
35467
|
}
|
|
34840
35468
|
function planLabel(planType) {
|
|
34841
35469
|
if (!planType)
|
|
@@ -34887,10 +35515,10 @@ function scrapeCodexHeaders(headers) {
|
|
|
34887
35515
|
}
|
|
34888
35516
|
function resolveProbeModel() {
|
|
34889
35517
|
try {
|
|
34890
|
-
const cachePath =
|
|
34891
|
-
if (!
|
|
35518
|
+
const cachePath = join18(homedir18(), ".codex", "models_cache.json");
|
|
35519
|
+
if (!existsSync15(cachePath))
|
|
34892
35520
|
return;
|
|
34893
|
-
const cache2 = JSON.parse(
|
|
35521
|
+
const cache2 = JSON.parse(readFileSync13(cachePath, "utf-8"));
|
|
34894
35522
|
for (const m of cache2.models ?? []) {
|
|
34895
35523
|
const slug = m?.slug ?? m?.id;
|
|
34896
35524
|
if (typeof slug === "string" && slug.length > 0)
|
|
@@ -34902,9 +35530,9 @@ function resolveProbeModel() {
|
|
|
34902
35530
|
function readCodexCredentials() {
|
|
34903
35531
|
try {
|
|
34904
35532
|
const path = credentialsPath();
|
|
34905
|
-
if (!
|
|
35533
|
+
if (!existsSync15(path))
|
|
34906
35534
|
return;
|
|
34907
|
-
return JSON.parse(
|
|
35535
|
+
return JSON.parse(readFileSync13(path, "utf-8"));
|
|
34908
35536
|
} catch {
|
|
34909
35537
|
return;
|
|
34910
35538
|
}
|
|
@@ -34935,7 +35563,7 @@ var init_codex = __esm(() => {
|
|
|
34935
35563
|
},
|
|
34936
35564
|
isAvailable() {
|
|
34937
35565
|
try {
|
|
34938
|
-
return
|
|
35566
|
+
return existsSync15(credentialsPath());
|
|
34939
35567
|
} catch {
|
|
34940
35568
|
return false;
|
|
34941
35569
|
}
|
|
@@ -35316,8 +35944,8 @@ var init_harness = __esm(() => {
|
|
|
35316
35944
|
|
|
35317
35945
|
// src/behavior/journal.ts
|
|
35318
35946
|
import { appendFile as appendFile2, mkdir, readFile, rename, stat, writeFile } from "fs/promises";
|
|
35319
|
-
import { homedir as
|
|
35320
|
-
import { dirname as dirname6, join as
|
|
35947
|
+
import { homedir as homedir19 } from "os";
|
|
35948
|
+
import { dirname as dirname6, join as join19 } from "path";
|
|
35321
35949
|
function classifyPath(observed, expected) {
|
|
35322
35950
|
if (!observed)
|
|
35323
35951
|
return "not_applicable";
|
|
@@ -35329,7 +35957,7 @@ function classifyPath(observed, expected) {
|
|
|
35329
35957
|
return dirOf(observed) === dirOf(expected) ? "same_dir_wrong_name" : "outside_expected_dir";
|
|
35330
35958
|
}
|
|
35331
35959
|
function journalPath() {
|
|
35332
|
-
return
|
|
35960
|
+
return join19(homedir19(), ".claudish", "behavior-journal.jsonl");
|
|
35333
35961
|
}
|
|
35334
35962
|
async function prune(path) {
|
|
35335
35963
|
const content = await readFile(path, "utf8");
|
|
@@ -35388,10 +36016,10 @@ __export(exports_aggregate, {
|
|
|
35388
36016
|
contextBucket: () => contextBucket,
|
|
35389
36017
|
TELEMETRY_SCHEMA_VERSION: () => TELEMETRY_SCHEMA_VERSION
|
|
35390
36018
|
});
|
|
35391
|
-
import { createHash as
|
|
35392
|
-
import { appendFileSync as appendFileSync2, mkdirSync as
|
|
35393
|
-
import { homedir as
|
|
35394
|
-
import { dirname as dirname7, join as
|
|
36019
|
+
import { createHash as createHash4, randomBytes as randomBytes4 } from "crypto";
|
|
36020
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync8 } from "fs";
|
|
36021
|
+
import { homedir as homedir20 } from "os";
|
|
36022
|
+
import { dirname as dirname7, join as join20 } from "path";
|
|
35395
36023
|
function contextBucket(inputTokens) {
|
|
35396
36024
|
if (inputTokens < 50000)
|
|
35397
36025
|
return "0-50k";
|
|
@@ -35412,7 +36040,7 @@ function contextFillPct(peakTokens, window2 = enforcedContextWindow) {
|
|
|
35412
36040
|
return Math.min(100, Math.max(0, Math.round(peakTokens / window2 * 100)));
|
|
35413
36041
|
}
|
|
35414
36042
|
function hashSessionId(rawSessionId, model) {
|
|
35415
|
-
return
|
|
36043
|
+
return createHash4("sha256").update(`${SESSION_SALT}:${rawSessionId}:${model}`).digest("hex");
|
|
35416
36044
|
}
|
|
35417
36045
|
function setTelemetryConsent(value) {
|
|
35418
36046
|
consent = value;
|
|
@@ -35509,7 +36137,7 @@ function pendingReports() {
|
|
|
35509
36137
|
return [...sessions.values()].map(toReport);
|
|
35510
36138
|
}
|
|
35511
36139
|
function outboxPath() {
|
|
35512
|
-
return
|
|
36140
|
+
return join20(homedir20(), ".claudish", "behavior-outbox.jsonl");
|
|
35513
36141
|
}
|
|
35514
36142
|
function spoolPendingSync(path = outboxPath()) {
|
|
35515
36143
|
if (sessions.size === 0)
|
|
@@ -35519,7 +36147,7 @@ function spoolPendingSync(path = outboxPath()) {
|
|
|
35519
36147
|
if (reports.length === 0)
|
|
35520
36148
|
return 0;
|
|
35521
36149
|
try {
|
|
35522
|
-
|
|
36150
|
+
mkdirSync8(dirname7(path), { recursive: true });
|
|
35523
36151
|
appendFileSync2(path, `${reports.map((r) => JSON.stringify(r)).join(`
|
|
35524
36152
|
`)}
|
|
35525
36153
|
`);
|
|
@@ -35532,7 +36160,7 @@ function spoolPendingSync(path = outboxPath()) {
|
|
|
35532
36160
|
var TELEMETRY_SCHEMA_VERSION = 1, enforcedContextWindow = 0, SESSION_SALT, MAX_TRACKED_SESSIONS = 32, MAX_DECISION_KEYS = 200, sessions, consent = false;
|
|
35533
36161
|
var init_aggregate = __esm(() => {
|
|
35534
36162
|
init_logger();
|
|
35535
|
-
SESSION_SALT =
|
|
36163
|
+
SESSION_SALT = randomBytes4(32).toString("hex");
|
|
35536
36164
|
sessions = new Map;
|
|
35537
36165
|
process.on("exit", () => {
|
|
35538
36166
|
try {
|
|
@@ -35737,10 +36365,10 @@ __export(exports_live_log, {
|
|
|
35737
36365
|
recordLiveDivergence: () => recordLiveDivergence
|
|
35738
36366
|
});
|
|
35739
36367
|
import { appendFile as appendFile3 } from "fs/promises";
|
|
35740
|
-
import { homedir as
|
|
35741
|
-
import { join as
|
|
36368
|
+
import { homedir as homedir21 } from "os";
|
|
36369
|
+
import { join as join21 } from "path";
|
|
35742
36370
|
function defaultPath() {
|
|
35743
|
-
return
|
|
36371
|
+
return join21(homedir21(), ".claudish", "behavior-divergences.jsonl");
|
|
35744
36372
|
}
|
|
35745
36373
|
async function recordLiveDivergence(entry, path = defaultPath()) {
|
|
35746
36374
|
try {
|
|
@@ -36436,9 +37064,9 @@ var init_hooks = __esm(() => {
|
|
|
36436
37064
|
});
|
|
36437
37065
|
|
|
36438
37066
|
// src/behavior/observer/corpus.ts
|
|
36439
|
-
import { appendFileSync as appendFileSync3, readFileSync as
|
|
36440
|
-
import { homedir as
|
|
36441
|
-
import { join as
|
|
37067
|
+
import { appendFileSync as appendFileSync3, readFileSync as readFileSync14, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
|
|
37068
|
+
import { homedir as homedir22 } from "os";
|
|
37069
|
+
import { join as join22 } from "path";
|
|
36442
37070
|
function directoryOf2(filePath) {
|
|
36443
37071
|
const slash = filePath.lastIndexOf("/");
|
|
36444
37072
|
return slash > 0 ? filePath.slice(0, slash) : undefined;
|
|
@@ -36460,7 +37088,7 @@ function writeTargetsOf(row) {
|
|
|
36460
37088
|
function replayTranscript(file2) {
|
|
36461
37089
|
let text;
|
|
36462
37090
|
try {
|
|
36463
|
-
text =
|
|
37091
|
+
text = readFileSync14(file2, "utf8");
|
|
36464
37092
|
} catch {
|
|
36465
37093
|
return [];
|
|
36466
37094
|
}
|
|
@@ -36517,26 +37145,26 @@ function listTranscripts(root) {
|
|
|
36517
37145
|
return files;
|
|
36518
37146
|
}
|
|
36519
37147
|
for (const project of projects) {
|
|
36520
|
-
const dir =
|
|
37148
|
+
const dir = join22(root, project);
|
|
36521
37149
|
try {
|
|
36522
37150
|
if (!statSync2(dir).isDirectory())
|
|
36523
37151
|
continue;
|
|
36524
37152
|
for (const f of readdirSync2(dir)) {
|
|
36525
37153
|
if (f.endsWith(".jsonl"))
|
|
36526
|
-
files.push(
|
|
37154
|
+
files.push(join22(dir, f));
|
|
36527
37155
|
}
|
|
36528
37156
|
} catch {}
|
|
36529
37157
|
}
|
|
36530
37158
|
return files;
|
|
36531
37159
|
}
|
|
36532
37160
|
function buildCorpus(options = {}) {
|
|
36533
|
-
const root = options.projectsRoot ??
|
|
37161
|
+
const root = options.projectsRoot ?? join22(homedir22(), ".claude", "projects");
|
|
36534
37162
|
const files = listTranscripts(root);
|
|
36535
37163
|
const records = [];
|
|
36536
37164
|
for (const f of files)
|
|
36537
37165
|
records.push(...replayTranscript(f));
|
|
36538
37166
|
if (options.write && records.length > 0) {
|
|
36539
|
-
const outputPath = options.outputPath ??
|
|
37167
|
+
const outputPath = options.outputPath ?? join22(homedir22(), ".claudish", "behavior-divergences.jsonl");
|
|
36540
37168
|
try {
|
|
36541
37169
|
appendFileSync3(outputPath, `${records.map((r) => JSON.stringify(r)).join(`
|
|
36542
37170
|
`)}
|
|
@@ -37311,25 +37939,25 @@ var init_model_parser = __esm(() => {
|
|
|
37311
37939
|
|
|
37312
37940
|
// src/stats-buffer.ts
|
|
37313
37941
|
import {
|
|
37314
|
-
existsSync as
|
|
37315
|
-
mkdirSync as
|
|
37316
|
-
readFileSync as
|
|
37317
|
-
renameSync,
|
|
37318
|
-
unlinkSync as
|
|
37319
|
-
writeFileSync as
|
|
37942
|
+
existsSync as existsSync16,
|
|
37943
|
+
mkdirSync as mkdirSync9,
|
|
37944
|
+
readFileSync as readFileSync15,
|
|
37945
|
+
renameSync as renameSync2,
|
|
37946
|
+
unlinkSync as unlinkSync5,
|
|
37947
|
+
writeFileSync as writeFileSync8
|
|
37320
37948
|
} from "fs";
|
|
37321
|
-
import { homedir as
|
|
37322
|
-
import { join as
|
|
37949
|
+
import { homedir as homedir23 } from "os";
|
|
37950
|
+
import { join as join23 } from "path";
|
|
37323
37951
|
function ensureDir() {
|
|
37324
|
-
if (!
|
|
37325
|
-
|
|
37952
|
+
if (!existsSync16(CLAUDISH_DIR)) {
|
|
37953
|
+
mkdirSync9(CLAUDISH_DIR, { recursive: true });
|
|
37326
37954
|
}
|
|
37327
37955
|
}
|
|
37328
37956
|
function readFromDisk() {
|
|
37329
37957
|
try {
|
|
37330
|
-
if (!
|
|
37958
|
+
if (!existsSync16(BUFFER_FILE))
|
|
37331
37959
|
return [];
|
|
37332
|
-
const raw =
|
|
37960
|
+
const raw = readFileSync15(BUFFER_FILE, "utf-8");
|
|
37333
37961
|
const parsed = JSON.parse(raw);
|
|
37334
37962
|
if (!Array.isArray(parsed.events))
|
|
37335
37963
|
return [];
|
|
@@ -37354,9 +37982,9 @@ function writeToDisk(events) {
|
|
|
37354
37982
|
ensureDir();
|
|
37355
37983
|
const trimmed2 = enforceSizeCap([...events]);
|
|
37356
37984
|
const payload = { version: 1, events: trimmed2 };
|
|
37357
|
-
const tmpFile =
|
|
37358
|
-
|
|
37359
|
-
|
|
37985
|
+
const tmpFile = join23(CLAUDISH_DIR, `stats-buffer.tmp.${process.pid}.json`);
|
|
37986
|
+
writeFileSync8(tmpFile, JSON.stringify(payload, null, 2), "utf-8");
|
|
37987
|
+
renameSync2(tmpFile, BUFFER_FILE);
|
|
37360
37988
|
memoryCache = trimmed2;
|
|
37361
37989
|
} catch {}
|
|
37362
37990
|
}
|
|
@@ -37398,8 +38026,8 @@ function clearBuffer() {
|
|
|
37398
38026
|
try {
|
|
37399
38027
|
memoryCache = [];
|
|
37400
38028
|
eventsSinceLastFlush = 0;
|
|
37401
|
-
if (
|
|
37402
|
-
|
|
38029
|
+
if (existsSync16(BUFFER_FILE)) {
|
|
38030
|
+
unlinkSync5(BUFFER_FILE);
|
|
37403
38031
|
}
|
|
37404
38032
|
} catch {}
|
|
37405
38033
|
}
|
|
@@ -37427,8 +38055,8 @@ function syncFlushOnExit() {
|
|
|
37427
38055
|
var BUFFER_MAX_BYTES, CLAUDISH_DIR, BUFFER_FILE, memoryCache = null, eventsSinceLastFlush = 0, flushScheduled = false;
|
|
37428
38056
|
var init_stats_buffer = __esm(() => {
|
|
37429
38057
|
BUFFER_MAX_BYTES = 64 * 1024;
|
|
37430
|
-
CLAUDISH_DIR =
|
|
37431
|
-
BUFFER_FILE =
|
|
38058
|
+
CLAUDISH_DIR = join23(homedir23(), ".claudish");
|
|
38059
|
+
BUFFER_FILE = join23(CLAUDISH_DIR, "stats-buffer.json");
|
|
37432
38060
|
process.on("exit", syncFlushOnExit);
|
|
37433
38061
|
process.on("SIGTERM", () => {
|
|
37434
38062
|
try {
|
|
@@ -37565,7 +38193,7 @@ __export(exports_telemetry, {
|
|
|
37565
38193
|
classifyError: () => classifyError,
|
|
37566
38194
|
buildReport: () => buildReport
|
|
37567
38195
|
});
|
|
37568
|
-
import { randomBytes as
|
|
38196
|
+
import { randomBytes as randomBytes5 } from "crypto";
|
|
37569
38197
|
function getVersion() {
|
|
37570
38198
|
return VERSION;
|
|
37571
38199
|
}
|
|
@@ -37833,7 +38461,7 @@ function initTelemetry(_config) {
|
|
|
37833
38461
|
} catch {
|
|
37834
38462
|
consentEnabled = false;
|
|
37835
38463
|
}
|
|
37836
|
-
sessionId =
|
|
38464
|
+
sessionId = randomBytes5(8).toString("hex");
|
|
37837
38465
|
claudishVersion = getVersion();
|
|
37838
38466
|
installMethod = detectInstallMethod();
|
|
37839
38467
|
}
|
|
@@ -38356,6 +38984,8 @@ function extractProviderMessage(body) {
|
|
|
38356
38984
|
function isTerminalError(status, bodyText, terminal429) {
|
|
38357
38985
|
if (status === 401 || status === 403)
|
|
38358
38986
|
return true;
|
|
38987
|
+
if (status === 426)
|
|
38988
|
+
return true;
|
|
38359
38989
|
if (status === 429 && terminal429)
|
|
38360
38990
|
return true;
|
|
38361
38991
|
const lower = (bodyText || "").toLowerCase();
|
|
@@ -40639,9 +41269,9 @@ var init_openai_responses_sse = __esm(() => {
|
|
|
40639
41269
|
});
|
|
40640
41270
|
|
|
40641
41271
|
// src/handlers/shared/token-tracker.ts
|
|
40642
|
-
import { mkdirSync as
|
|
40643
|
-
import { homedir as
|
|
40644
|
-
import { dirname as dirname8, join as
|
|
41272
|
+
import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync9 } from "fs";
|
|
41273
|
+
import { homedir as homedir24 } from "os";
|
|
41274
|
+
import { dirname as dirname8, join as join24 } from "path";
|
|
40645
41275
|
function stripProviderPrefix(name) {
|
|
40646
41276
|
const at = name.indexOf("@");
|
|
40647
41277
|
return at === -1 ? name : name.slice(at + 1);
|
|
@@ -40829,9 +41459,9 @@ class TokenTracker {
|
|
|
40829
41459
|
};
|
|
40830
41460
|
}
|
|
40831
41461
|
const override = process.env.CLAUDISH_TOKEN_FILE;
|
|
40832
|
-
const outPath = override ||
|
|
40833
|
-
|
|
40834
|
-
|
|
41462
|
+
const outPath = override || join24(homedir24(), ".claudish", `tokens-${this.port}.json`);
|
|
41463
|
+
mkdirSync10(dirname8(outPath), { recursive: true });
|
|
41464
|
+
writeFileSync9(outPath, JSON.stringify(data), "utf-8");
|
|
40835
41465
|
} catch (e) {
|
|
40836
41466
|
log(`[TokenTracker] Error writing token file: ${e}`);
|
|
40837
41467
|
}
|
|
@@ -44089,7 +44719,7 @@ var init_default_routing_rules = __esm(() => {
|
|
|
44089
44719
|
"o1-*": ["openai-codex", "openai", "openrouter"],
|
|
44090
44720
|
"o3-*": ["openai-codex", "openai", "openrouter"],
|
|
44091
44721
|
"gemini-*": ["antigravity", "google", "openrouter"],
|
|
44092
|
-
"grok-*": ["x-ai", "openrouter"],
|
|
44722
|
+
"grok-*": ["grok-subscription", "x-ai", "openrouter"],
|
|
44093
44723
|
"kimi-*": ["kimi-coding", "opencode-zen-go", "kimi", "openrouter"],
|
|
44094
44724
|
"k3*": ["kimi-coding", "opencode-zen-go", "kimi", "openrouter"],
|
|
44095
44725
|
"minimax-*": ["minimax-coding", "opencode-zen-go", "minimax", "openrouter"],
|
|
@@ -45012,9 +45642,9 @@ var CLAUDISH_BIN_ENV = "CLAUDISH_BIN";
|
|
|
45012
45642
|
// src/channel/session-manager.ts
|
|
45013
45643
|
import { spawn } from "child_process";
|
|
45014
45644
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
45015
|
-
import { createWriteStream, mkdirSync as
|
|
45016
|
-
import { homedir as
|
|
45017
|
-
import { join as
|
|
45645
|
+
import { createWriteStream, mkdirSync as mkdirSync11, writeFileSync as writeFileSync10 } from "fs";
|
|
45646
|
+
import { homedir as homedir25 } from "os";
|
|
45647
|
+
import { join as join25 } from "path";
|
|
45018
45648
|
|
|
45019
45649
|
class SessionManager {
|
|
45020
45650
|
sessions = new Map;
|
|
@@ -45026,7 +45656,7 @@ class SessionManager {
|
|
|
45026
45656
|
constructor(options) {
|
|
45027
45657
|
this.maxSessions = options?.maxSessions ?? DEFAULT_MAX_SESSIONS;
|
|
45028
45658
|
this.scrollbackCapacity = options?.scrollbackCapacity ?? DEFAULT_SCROLLBACK;
|
|
45029
|
-
this.sessionsDir = options?.sessionsDir ?? process.env.CLAUDISH_SESSIONS_DIR ??
|
|
45659
|
+
this.sessionsDir = options?.sessionsDir ?? process.env.CLAUDISH_SESSIONS_DIR ?? join25(homedir25(), ".claudish", "sessions");
|
|
45030
45660
|
this.onStateChange = options?.onStateChange;
|
|
45031
45661
|
}
|
|
45032
45662
|
createSession(opts) {
|
|
@@ -45036,10 +45666,10 @@ class SessionManager {
|
|
|
45036
45666
|
const sessionId2 = randomUUID4().slice(0, 8);
|
|
45037
45667
|
const timeout = Math.min(opts.timeoutSeconds ?? DEFAULT_TIMEOUT, MAX_TIMEOUT);
|
|
45038
45668
|
const startedAt = new Date().toISOString();
|
|
45039
|
-
const sessionDir =
|
|
45040
|
-
|
|
45669
|
+
const sessionDir = join25(this.sessionsDir, sessionId2);
|
|
45670
|
+
mkdirSync11(sessionDir, { recursive: true });
|
|
45041
45671
|
if (opts.prompt) {
|
|
45042
|
-
|
|
45672
|
+
writeFileSync10(join25(sessionDir, "prompt.md"), opts.prompt, "utf-8");
|
|
45043
45673
|
}
|
|
45044
45674
|
const args = [
|
|
45045
45675
|
"--model",
|
|
@@ -45075,7 +45705,7 @@ class SessionManager {
|
|
|
45075
45705
|
});
|
|
45076
45706
|
}
|
|
45077
45707
|
});
|
|
45078
|
-
const outputLogStream = createWriteStream(
|
|
45708
|
+
const outputLogStream = createWriteStream(join25(sessionDir, "output.log"));
|
|
45079
45709
|
const entry = {
|
|
45080
45710
|
info: {
|
|
45081
45711
|
sessionId: sessionId2,
|
|
@@ -45122,9 +45752,9 @@ class SessionManager {
|
|
|
45122
45752
|
watcher.processExited(code);
|
|
45123
45753
|
outputLogStream.end();
|
|
45124
45754
|
if (entry.stderr) {
|
|
45125
|
-
|
|
45755
|
+
writeFileSync10(join25(sessionDir, "stderr.log"), entry.stderr, "utf-8");
|
|
45126
45756
|
}
|
|
45127
|
-
|
|
45757
|
+
writeFileSync10(join25(sessionDir, "meta.json"), JSON.stringify(entry.info, null, 2), "utf-8");
|
|
45128
45758
|
this.cleanupSigint();
|
|
45129
45759
|
});
|
|
45130
45760
|
proc.on("error", (err) => {
|
|
@@ -45434,9 +46064,9 @@ function compareByReleaseDateDesc(a, b) {
|
|
|
45434
46064
|
}
|
|
45435
46065
|
|
|
45436
46066
|
// src/model-loader.ts
|
|
45437
|
-
import { existsSync as
|
|
45438
|
-
import { homedir as
|
|
45439
|
-
import { join as
|
|
46067
|
+
import { existsSync as existsSync17, mkdirSync as mkdirSync12, readFileSync as readFileSync16, writeFileSync as writeFileSync11 } from "fs";
|
|
46068
|
+
import { homedir as homedir26 } from "os";
|
|
46069
|
+
import { join as join26 } from "path";
|
|
45440
46070
|
function groupRecommendedModels(entries) {
|
|
45441
46071
|
const byId = new Map;
|
|
45442
46072
|
const categoryOrder = new Map;
|
|
@@ -45546,9 +46176,9 @@ async function getRecommendedModels(opts = {}) {
|
|
|
45546
46176
|
if (!forceRefresh && _cachedRecommendedModels) {
|
|
45547
46177
|
return _cachedRecommendedModels;
|
|
45548
46178
|
}
|
|
45549
|
-
if (!forceRefresh &&
|
|
46179
|
+
if (!forceRefresh && existsSync17(RECOMMENDED_MODELS_CACHE_PATH)) {
|
|
45550
46180
|
try {
|
|
45551
|
-
const cacheData = JSON.parse(
|
|
46181
|
+
const cacheData = JSON.parse(readFileSync16(RECOMMENDED_MODELS_CACHE_PATH, "utf-8"));
|
|
45552
46182
|
if (cacheData.models && cacheData.models.length > 0 && isFreshEnough(cacheData)) {
|
|
45553
46183
|
_cachedRecommendedModels = cacheData;
|
|
45554
46184
|
return cacheData;
|
|
@@ -45564,9 +46194,9 @@ async function getRecommendedModels(opts = {}) {
|
|
|
45564
46194
|
if (data.models && data.models.length > 0) {
|
|
45565
46195
|
_cachedRecommendedModels = data;
|
|
45566
46196
|
try {
|
|
45567
|
-
const cacheDir =
|
|
45568
|
-
|
|
45569
|
-
|
|
46197
|
+
const cacheDir = join26(homedir26(), ".claudish");
|
|
46198
|
+
mkdirSync12(cacheDir, { recursive: true });
|
|
46199
|
+
writeFileSync11(RECOMMENDED_MODELS_CACHE_PATH, JSON.stringify(data), "utf-8");
|
|
45570
46200
|
} catch {}
|
|
45571
46201
|
return data;
|
|
45572
46202
|
}
|
|
@@ -45577,9 +46207,9 @@ async function getRecommendedModels(opts = {}) {
|
|
|
45577
46207
|
function getRecommendedModelsSync() {
|
|
45578
46208
|
if (_cachedRecommendedModels)
|
|
45579
46209
|
return _cachedRecommendedModels;
|
|
45580
|
-
if (
|
|
46210
|
+
if (existsSync17(RECOMMENDED_MODELS_CACHE_PATH)) {
|
|
45581
46211
|
try {
|
|
45582
|
-
const cacheData = JSON.parse(
|
|
46212
|
+
const cacheData = JSON.parse(readFileSync16(RECOMMENDED_MODELS_CACHE_PATH, "utf-8"));
|
|
45583
46213
|
if (cacheData.models && cacheData.models.length > 0 && isFreshEnough(cacheData)) {
|
|
45584
46214
|
_cachedRecommendedModels = cacheData;
|
|
45585
46215
|
return cacheData;
|
|
@@ -45703,7 +46333,7 @@ var _cachedModelInfo = null, _cachedModelIds = null, _cachedRecommendedModels =
|
|
|
45703
46333
|
var init_model_loader = __esm(() => {
|
|
45704
46334
|
init_cache_ttl();
|
|
45705
46335
|
FIREBASE_RECOMMENDED_URL = `${FIREBASE_BASE_URL}?catalog=recommended`;
|
|
45706
|
-
RECOMMENDED_MODELS_CACHE_PATH =
|
|
46336
|
+
RECOMMENDED_MODELS_CACHE_PATH = join26(homedir26(), ".claudish", "recommended-models-cache.json");
|
|
45707
46337
|
FIREBASE_SLUG_TO_PROVIDER_NAME = {
|
|
45708
46338
|
openai: "openai",
|
|
45709
46339
|
google: "google",
|
|
@@ -45922,11 +46552,11 @@ var splitPath = (path) => {
|
|
|
45922
46552
|
return patternCache[cacheKey];
|
|
45923
46553
|
}
|
|
45924
46554
|
return null;
|
|
45925
|
-
}, tryDecode = (
|
|
46555
|
+
}, tryDecode = (str2, decoder) => {
|
|
45926
46556
|
try {
|
|
45927
|
-
return decoder(
|
|
46557
|
+
return decoder(str2);
|
|
45928
46558
|
} catch {
|
|
45929
|
-
return
|
|
46559
|
+
return str2.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
45930
46560
|
try {
|
|
45931
46561
|
return decoder(match);
|
|
45932
46562
|
} catch {
|
|
@@ -45934,7 +46564,7 @@ var splitPath = (path) => {
|
|
|
45934
46564
|
}
|
|
45935
46565
|
});
|
|
45936
46566
|
}
|
|
45937
|
-
}, tryDecodeURI = (
|
|
46567
|
+
}, tryDecodeURI = (str2) => tryDecode(str2, decodeURI), getPath = (request) => {
|
|
45938
46568
|
const url2 = request.url;
|
|
45939
46569
|
const start = url2.indexOf("/", url2.indexOf(":") + 4);
|
|
45940
46570
|
let i = start;
|
|
@@ -46063,7 +46693,7 @@ var init_url = __esm(() => {
|
|
|
46063
46693
|
});
|
|
46064
46694
|
|
|
46065
46695
|
// ../../node_modules/.bun/hono@4.10.6/node_modules/hono/dist/request.js
|
|
46066
|
-
var tryDecodeURIComponent = (
|
|
46696
|
+
var tryDecodeURIComponent = (str2) => tryDecode(str2, decodeURIComponent_), HonoRequest;
|
|
46067
46697
|
var init_request = __esm(() => {
|
|
46068
46698
|
init_http_exception();
|
|
46069
46699
|
init_constants();
|
|
@@ -46185,25 +46815,25 @@ var HtmlEscapedCallbackPhase, raw = (value, callbacks) => {
|
|
|
46185
46815
|
escapedString.isEscaped = true;
|
|
46186
46816
|
escapedString.callbacks = callbacks;
|
|
46187
46817
|
return escapedString;
|
|
46188
|
-
}, resolveCallback = async (
|
|
46189
|
-
if (typeof
|
|
46190
|
-
if (!(
|
|
46191
|
-
|
|
46818
|
+
}, resolveCallback = async (str2, phase, preserveCallbacks, context, buffer) => {
|
|
46819
|
+
if (typeof str2 === "object" && !(str2 instanceof String)) {
|
|
46820
|
+
if (!(str2 instanceof Promise)) {
|
|
46821
|
+
str2 = str2.toString();
|
|
46192
46822
|
}
|
|
46193
|
-
if (
|
|
46194
|
-
|
|
46823
|
+
if (str2 instanceof Promise) {
|
|
46824
|
+
str2 = await str2;
|
|
46195
46825
|
}
|
|
46196
46826
|
}
|
|
46197
|
-
const callbacks =
|
|
46827
|
+
const callbacks = str2.callbacks;
|
|
46198
46828
|
if (!callbacks?.length) {
|
|
46199
|
-
return Promise.resolve(
|
|
46829
|
+
return Promise.resolve(str2);
|
|
46200
46830
|
}
|
|
46201
46831
|
if (buffer) {
|
|
46202
|
-
buffer[0] +=
|
|
46832
|
+
buffer[0] += str2;
|
|
46203
46833
|
} else {
|
|
46204
|
-
buffer = [
|
|
46834
|
+
buffer = [str2];
|
|
46205
46835
|
}
|
|
46206
|
-
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then((res) => Promise.all(res.filter(Boolean).map((
|
|
46836
|
+
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
46837
|
if (preserveCallbacks) {
|
|
46208
46838
|
return raw(await resStr, callbacks);
|
|
46209
46839
|
} else {
|
|
@@ -48868,11 +49498,11 @@ var init_ollama_api_format = __esm(() => {
|
|
|
48868
49498
|
});
|
|
48869
49499
|
|
|
48870
49500
|
// src/providers/api-key-provenance.ts
|
|
48871
|
-
import { existsSync as
|
|
48872
|
-
import { homedir as
|
|
48873
|
-
import { join as
|
|
49501
|
+
import { existsSync as existsSync18, readFileSync as readFileSync17 } from "fs";
|
|
49502
|
+
import { homedir as homedir27 } from "os";
|
|
49503
|
+
import { join as join27, resolve as resolve2 } from "path";
|
|
48874
49504
|
function activeConfigPath() {
|
|
48875
|
-
return activeGlobalConfigFile(
|
|
49505
|
+
return activeGlobalConfigFile(join27(homedir27(), ".claudish", "config.json"));
|
|
48876
49506
|
}
|
|
48877
49507
|
function configLayerLabel() {
|
|
48878
49508
|
return getConfigFileOverride() ? activeConfigPath() : "~/.claudish/config.json";
|
|
@@ -48949,9 +49579,9 @@ function formatProvenanceLog(p) {
|
|
|
48949
49579
|
function readDotenvKey(envVars) {
|
|
48950
49580
|
try {
|
|
48951
49581
|
const dotenvPath = resolve2(".env");
|
|
48952
|
-
if (!
|
|
49582
|
+
if (!existsSync18(dotenvPath))
|
|
48953
49583
|
return null;
|
|
48954
|
-
const parsed = import_dotenv.parse(
|
|
49584
|
+
const parsed = import_dotenv.parse(readFileSync17(dotenvPath, "utf-8"));
|
|
48955
49585
|
for (const v of envVars) {
|
|
48956
49586
|
if (parsed[v])
|
|
48957
49587
|
return parsed[v];
|
|
@@ -48964,9 +49594,9 @@ function readDotenvKey(envVars) {
|
|
|
48964
49594
|
function readConfigKey(envVar) {
|
|
48965
49595
|
try {
|
|
48966
49596
|
const configPath = activeConfigPath();
|
|
48967
|
-
if (!
|
|
49597
|
+
if (!existsSync18(configPath))
|
|
48968
49598
|
return null;
|
|
48969
|
-
const cfg = JSON.parse(
|
|
49599
|
+
const cfg = JSON.parse(readFileSync17(configPath, "utf-8"));
|
|
48970
49600
|
return cfg.apiKeys?.[envVar] || null;
|
|
48971
49601
|
} catch {
|
|
48972
49602
|
return null;
|
|
@@ -49152,6 +49782,29 @@ var init_gemini_apikey = __esm(() => {
|
|
|
49152
49782
|
init_gemini_queue();
|
|
49153
49783
|
});
|
|
49154
49784
|
|
|
49785
|
+
// src/providers/transport/grok-subscription.ts
|
|
49786
|
+
var GrokSubscriptionProviderTransport;
|
|
49787
|
+
var init_grok_subscription = __esm(() => {
|
|
49788
|
+
init_authority();
|
|
49789
|
+
init_grok_credentials();
|
|
49790
|
+
init_openai();
|
|
49791
|
+
GrokSubscriptionProviderTransport = class GrokSubscriptionProviderTransport extends OpenAIProviderTransport {
|
|
49792
|
+
async getHeaders() {
|
|
49793
|
+
const auth = await credentials.getRequestAuth("grok-subscription", {
|
|
49794
|
+
model: this.modelName
|
|
49795
|
+
});
|
|
49796
|
+
const headers = { ...auth.headers };
|
|
49797
|
+
if (this.provider.headers) {
|
|
49798
|
+
Object.assign(headers, this.provider.headers);
|
|
49799
|
+
}
|
|
49800
|
+
return headers;
|
|
49801
|
+
}
|
|
49802
|
+
async forceRefreshAuth() {
|
|
49803
|
+
await forceRefreshGrokAccessToken();
|
|
49804
|
+
}
|
|
49805
|
+
};
|
|
49806
|
+
});
|
|
49807
|
+
|
|
49155
49808
|
// src/providers/transport/ollamacloud.ts
|
|
49156
49809
|
class OllamaProviderTransport {
|
|
49157
49810
|
name = "ollamacloud";
|
|
@@ -49312,7 +49965,7 @@ function createHandlerForProvider(ctx) {
|
|
|
49312
49965
|
log(`[Proxy] Handler: provider=${ctx.provider.name}, model=${ctx.modelName}`);
|
|
49313
49966
|
return profile.createHandler(ctx);
|
|
49314
49967
|
}
|
|
49315
|
-
var geminiProfile, antigravityProfile, devinProfile, openaiProfile, openaiCodexProfile, anthropicCompatProfile, glmProfile, openCodeZenProfile, ollamaCloudProfile, litellmProfile, vertexProfile, PROVIDER_PROFILES;
|
|
49968
|
+
var geminiProfile, antigravityProfile, devinProfile, grokSubscriptionProfile, openaiProfile, openaiCodexProfile, anthropicCompatProfile, glmProfile, openCodeZenProfile, ollamaCloudProfile, litellmProfile, vertexProfile, PROVIDER_PROFILES;
|
|
49316
49969
|
var init_provider_profiles = __esm(() => {
|
|
49317
49970
|
init_anthropic_api_format();
|
|
49318
49971
|
init_base_api_format();
|
|
@@ -49332,6 +49985,7 @@ var init_provider_profiles = __esm(() => {
|
|
|
49332
49985
|
init_antigravity();
|
|
49333
49986
|
init_devin2();
|
|
49334
49987
|
init_gemini_apikey();
|
|
49988
|
+
init_grok_subscription();
|
|
49335
49989
|
init_litellm();
|
|
49336
49990
|
init_ollamacloud();
|
|
49337
49991
|
init_openai_codex();
|
|
@@ -49375,6 +50029,19 @@ var init_provider_profiles = __esm(() => {
|
|
|
49375
50029
|
return handler;
|
|
49376
50030
|
}
|
|
49377
50031
|
};
|
|
50032
|
+
grokSubscriptionProfile = {
|
|
50033
|
+
createHandler(ctx) {
|
|
50034
|
+
const transport = new GrokSubscriptionProviderTransport(ctx.provider, ctx.modelName, "");
|
|
50035
|
+
const adapter = new OpenAIAPIFormat(ctx.modelName);
|
|
50036
|
+
const handler = new ComposedHandler(transport, ctx.targetModel, ctx.modelName, ctx.port, {
|
|
50037
|
+
adapter,
|
|
50038
|
+
tokenStrategy: "delta-aware",
|
|
50039
|
+
...ctx.sharedOpts
|
|
50040
|
+
});
|
|
50041
|
+
log(`[Proxy] Created Grok subscription handler (composed): ${ctx.modelName}`);
|
|
50042
|
+
return handler;
|
|
50043
|
+
}
|
|
50044
|
+
};
|
|
49378
50045
|
openaiProfile = {
|
|
49379
50046
|
createHandler(ctx) {
|
|
49380
50047
|
if (requiresResponsesApi(ctx.modelName)) {
|
|
@@ -49547,6 +50214,7 @@ var init_provider_profiles = __esm(() => {
|
|
|
49547
50214
|
openai: openaiProfile,
|
|
49548
50215
|
"openai-codex": openaiCodexProfile,
|
|
49549
50216
|
"x-ai": openaiProfile,
|
|
50217
|
+
"grok-subscription": grokSubscriptionProfile,
|
|
49550
50218
|
qwen: openaiProfile,
|
|
49551
50219
|
minimax: anthropicCompatProfile,
|
|
49552
50220
|
"minimax-coding": anthropicCompatProfile,
|
|
@@ -50284,9 +50952,9 @@ var init_poe = __esm(() => {
|
|
|
50284
50952
|
});
|
|
50285
50953
|
|
|
50286
50954
|
// src/services/pricing-cache.ts
|
|
50287
|
-
import { existsSync as
|
|
50288
|
-
import { homedir as
|
|
50289
|
-
import { join as
|
|
50955
|
+
import { existsSync as existsSync19, readFileSync as readFileSync18, statSync as statSync4 } from "fs";
|
|
50956
|
+
import { homedir as homedir28 } from "os";
|
|
50957
|
+
import { join as join28 } from "path";
|
|
50290
50958
|
function prefixMatch(modelName) {
|
|
50291
50959
|
for (const [key, pricing] of pricingMap) {
|
|
50292
50960
|
if (modelName.startsWith(key))
|
|
@@ -50324,12 +50992,12 @@ async function warmPricingCache() {
|
|
|
50324
50992
|
}
|
|
50325
50993
|
function loadDiskCache() {
|
|
50326
50994
|
try {
|
|
50327
|
-
if (!
|
|
50995
|
+
if (!existsSync19(CACHE_FILE))
|
|
50328
50996
|
return false;
|
|
50329
50997
|
const stat2 = statSync4(CACHE_FILE);
|
|
50330
50998
|
const age = Date.now() - stat2.mtimeMs;
|
|
50331
50999
|
const isFresh = age < CACHE_TTL_MS3;
|
|
50332
|
-
const raw2 =
|
|
51000
|
+
const raw2 = readFileSync18(CACHE_FILE, "utf-8");
|
|
50333
51001
|
const data = JSON.parse(raw2);
|
|
50334
51002
|
for (const [key, pricing] of Object.entries(data)) {
|
|
50335
51003
|
pricingMap.set(key, pricing);
|
|
@@ -50345,8 +51013,8 @@ var init_pricing_cache = __esm(() => {
|
|
|
50345
51013
|
init_logger();
|
|
50346
51014
|
init_catalog_query();
|
|
50347
51015
|
pricingMap = new Map;
|
|
50348
|
-
CACHE_DIR =
|
|
50349
|
-
CACHE_FILE =
|
|
51016
|
+
CACHE_DIR = join28(homedir28(), ".claudish");
|
|
51017
|
+
CACHE_FILE = join28(CACHE_DIR, "pricing-cache.json");
|
|
50350
51018
|
CACHE_TTL_MS3 = 24 * 60 * 60 * 1000;
|
|
50351
51019
|
});
|
|
50352
51020
|
|
|
@@ -50871,20 +51539,20 @@ var init_redact = __esm(() => {
|
|
|
50871
51539
|
});
|
|
50872
51540
|
|
|
50873
51541
|
// src/team-stats.ts
|
|
50874
|
-
import { existsSync as
|
|
50875
|
-
import { join as
|
|
51542
|
+
import { existsSync as existsSync20, readFileSync as readFileSync19, writeFileSync as writeFileSync12 } from "fs";
|
|
51543
|
+
import { join as join29 } from "path";
|
|
50876
51544
|
function statsDir(sessionPath) {
|
|
50877
|
-
return
|
|
51545
|
+
return join29(sessionPath, "stats");
|
|
50878
51546
|
}
|
|
50879
51547
|
function tokenFileFor(sessionPath, anonId) {
|
|
50880
|
-
return
|
|
51548
|
+
return join29(statsDir(sessionPath), `${anonId}.json`);
|
|
50881
51549
|
}
|
|
50882
51550
|
function readTokenStats(sessionPath, anonId) {
|
|
50883
51551
|
const path = tokenFileFor(sessionPath, anonId);
|
|
50884
|
-
if (!
|
|
51552
|
+
if (!existsSync20(path))
|
|
50885
51553
|
return null;
|
|
50886
51554
|
try {
|
|
50887
|
-
return JSON.parse(
|
|
51555
|
+
return JSON.parse(readFileSync19(path, "utf-8"));
|
|
50888
51556
|
} catch {
|
|
50889
51557
|
return null;
|
|
50890
51558
|
}
|
|
@@ -51032,7 +51700,7 @@ ${segs.join(" \xB7 ")}`;
|
|
|
51032
51700
|
}
|
|
51033
51701
|
function writeStatusFile(sessionPath, manifest, status, opts) {
|
|
51034
51702
|
try {
|
|
51035
|
-
|
|
51703
|
+
writeFileSync12(join29(sessionPath, "status.txt"), `${renderTeamStats(sessionPath, manifest, status, opts)}
|
|
51036
51704
|
`, "utf-8");
|
|
51037
51705
|
} catch {}
|
|
51038
51706
|
}
|
|
@@ -51183,13 +51851,13 @@ __export(exports_team_orchestrator, {
|
|
|
51183
51851
|
import { spawn as spawn2 } from "child_process";
|
|
51184
51852
|
import {
|
|
51185
51853
|
createWriteStream as createWriteStream2,
|
|
51186
|
-
existsSync as
|
|
51187
|
-
mkdirSync as
|
|
51188
|
-
readFileSync as
|
|
51854
|
+
existsSync as existsSync21,
|
|
51855
|
+
mkdirSync as mkdirSync13,
|
|
51856
|
+
readFileSync as readFileSync20,
|
|
51189
51857
|
readdirSync as readdirSync3,
|
|
51190
|
-
writeFileSync as
|
|
51858
|
+
writeFileSync as writeFileSync13
|
|
51191
51859
|
} from "fs";
|
|
51192
|
-
import { join as
|
|
51860
|
+
import { join as join30, resolve as resolve3 } from "path";
|
|
51193
51861
|
function resolveCaptureMode(explicit, env = process.env) {
|
|
51194
51862
|
if (explicit)
|
|
51195
51863
|
return explicit;
|
|
@@ -51262,7 +51930,7 @@ function persistErrorLog(errorLogPath, header, stderr, stdoutTail) {
|
|
|
51262
51930
|
parts.push("--- stderr ---", stderr.trim() ? redactSecrets(stderr) : "(empty)", "");
|
|
51263
51931
|
parts.push("--- stdout (tail) ---", stdoutTail.trim() ? redactSecrets(stdoutTail) : "(empty)", "");
|
|
51264
51932
|
try {
|
|
51265
|
-
|
|
51933
|
+
writeFileSync13(errorLogPath, parts.join(`
|
|
51266
51934
|
`), "utf-8");
|
|
51267
51935
|
} catch {}
|
|
51268
51936
|
}
|
|
@@ -51286,18 +51954,18 @@ function setupSession(sessionPath, models, input) {
|
|
|
51286
51954
|
if (models.length === 0) {
|
|
51287
51955
|
throw new Error("At least one model is required");
|
|
51288
51956
|
}
|
|
51289
|
-
if (
|
|
51957
|
+
if (existsSync21(join30(sessionPath, "manifest.json"))) {
|
|
51290
51958
|
throw new Error(`Session already exists at ${sessionPath}. Use a new directory path or delete the existing session first.`);
|
|
51291
51959
|
}
|
|
51292
51960
|
const sentinels = models.filter(isSentinelModel);
|
|
51293
51961
|
if (sentinels.length > 0) {
|
|
51294
51962
|
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
51963
|
}
|
|
51296
|
-
|
|
51297
|
-
|
|
51964
|
+
mkdirSync13(join30(sessionPath, "work"), { recursive: true });
|
|
51965
|
+
mkdirSync13(join30(sessionPath, "errors"), { recursive: true });
|
|
51298
51966
|
if (input !== undefined) {
|
|
51299
|
-
|
|
51300
|
-
} else if (!
|
|
51967
|
+
writeFileSync13(join30(sessionPath, "input.md"), input, "utf-8");
|
|
51968
|
+
} else if (!existsSync21(join30(sessionPath, "input.md"))) {
|
|
51301
51969
|
throw new Error(`No input.md found at ${sessionPath} and no input provided`);
|
|
51302
51970
|
}
|
|
51303
51971
|
const ids = models.map((_, i) => String(i + 1).padStart(2, "0"));
|
|
@@ -51314,9 +51982,9 @@ function setupSession(sessionPath, models, input) {
|
|
|
51314
51982
|
model: models[i],
|
|
51315
51983
|
assignedAt: now
|
|
51316
51984
|
};
|
|
51317
|
-
|
|
51985
|
+
mkdirSync13(join30(sessionPath, "work", anonId), { recursive: true });
|
|
51318
51986
|
}
|
|
51319
|
-
|
|
51987
|
+
writeFileSync13(join30(sessionPath, "manifest.json"), JSON.stringify(manifest, null, 2), "utf-8");
|
|
51320
51988
|
const status = {
|
|
51321
51989
|
startedAt: now,
|
|
51322
51990
|
models: Object.fromEntries(Object.keys(manifest.models).map((id) => [
|
|
@@ -51330,7 +51998,7 @@ function setupSession(sessionPath, models, input) {
|
|
|
51330
51998
|
}
|
|
51331
51999
|
]))
|
|
51332
52000
|
};
|
|
51333
|
-
|
|
52001
|
+
writeFileSync13(join30(sessionPath, "status.json"), JSON.stringify(status, null, 2), "utf-8");
|
|
51334
52002
|
return manifest;
|
|
51335
52003
|
}
|
|
51336
52004
|
function assertValidRequirePattern(pattern) {
|
|
@@ -51347,7 +52015,7 @@ function readFullOutputIfNeeded(opts) {
|
|
|
51347
52015
|
if (crashed || !requirePattern || outputSize <= STDOUT_TAIL_LIMIT)
|
|
51348
52016
|
return;
|
|
51349
52017
|
try {
|
|
51350
|
-
return
|
|
52018
|
+
return readFileSync20(outputPath, "utf-8");
|
|
51351
52019
|
} catch {
|
|
51352
52020
|
return;
|
|
51353
52021
|
}
|
|
@@ -51355,15 +52023,15 @@ function readFullOutputIfNeeded(opts) {
|
|
|
51355
52023
|
async function runModels(sessionPath, opts = {}) {
|
|
51356
52024
|
const timeoutMs = (opts.timeout ?? 300) * 1000;
|
|
51357
52025
|
assertValidRequirePattern(opts.requirePattern);
|
|
51358
|
-
const manifest = JSON.parse(
|
|
51359
|
-
const statusPath =
|
|
51360
|
-
const inputPath =
|
|
51361
|
-
const inputContent =
|
|
52026
|
+
const manifest = JSON.parse(readFileSync20(join30(sessionPath, "manifest.json"), "utf-8"));
|
|
52027
|
+
const statusPath = join30(sessionPath, "status.json");
|
|
52028
|
+
const inputPath = join30(sessionPath, "input.md");
|
|
52029
|
+
const inputContent = readFileSync20(inputPath, "utf-8");
|
|
51362
52030
|
const spawnPlan = await (opts.spawnPlanner ?? prehydrateCredentialsForSpawn)(Object.values(manifest.models).map((m) => m.model));
|
|
51363
|
-
const statusCache = JSON.parse(
|
|
52031
|
+
const statusCache = JSON.parse(readFileSync20(statusPath, "utf-8"));
|
|
51364
52032
|
function updateModelStatus(id, update) {
|
|
51365
52033
|
statusCache.models[id] = { ...statusCache.models[id], ...update };
|
|
51366
|
-
|
|
52034
|
+
writeFileSync13(statusPath, JSON.stringify(statusCache, null, 2), "utf-8");
|
|
51367
52035
|
}
|
|
51368
52036
|
const minOutputBytes = opts.minOutputBytes ?? DEFAULT_MIN_OUTPUT_BYTES;
|
|
51369
52037
|
const requirePattern = opts.requirePattern;
|
|
@@ -51396,7 +52064,7 @@ async function runModels(sessionPath, opts = {}) {
|
|
|
51396
52064
|
persistErrorLog(rt.errorLogPath, `RECOVERED: ${note}`, stderr, stdoutTail);
|
|
51397
52065
|
opts.onStatusChange?.(id, statusCache.models[id]);
|
|
51398
52066
|
}
|
|
51399
|
-
|
|
52067
|
+
mkdirSync13(statsDir(sessionPath), { recursive: true });
|
|
51400
52068
|
const processes = new Map;
|
|
51401
52069
|
const runtimes = new Map;
|
|
51402
52070
|
const sigintHandler = () => {
|
|
@@ -51408,8 +52076,8 @@ async function runModels(sessionPath, opts = {}) {
|
|
|
51408
52076
|
process.on("SIGINT", sigintHandler);
|
|
51409
52077
|
const completionPromises = [];
|
|
51410
52078
|
for (const [anonId, entry] of Object.entries(manifest.models)) {
|
|
51411
|
-
const outputPath =
|
|
51412
|
-
const errorLogPath =
|
|
52079
|
+
const outputPath = join30(sessionPath, `response-${anonId}.md`);
|
|
52080
|
+
const errorLogPath = join30(sessionPath, "errors", `${anonId}.log`);
|
|
51413
52081
|
const spawnModel = spawnPlan.pinned.get(entry.model) ?? entry.model;
|
|
51414
52082
|
const args = [
|
|
51415
52083
|
"--model",
|
|
@@ -51548,7 +52216,7 @@ async function runModels(sessionPath, opts = {}) {
|
|
|
51548
52216
|
proc.on("exit", (code) => {
|
|
51549
52217
|
const timedOut = statusCache.models[anonId]?.state === "TIMEOUT";
|
|
51550
52218
|
if (!timedOut && meaningfulStderr(stderr)) {
|
|
51551
|
-
|
|
52219
|
+
writeFileSync13(errorLogPath, redactSecrets(stderr), "utf-8");
|
|
51552
52220
|
}
|
|
51553
52221
|
exitCode = code;
|
|
51554
52222
|
if (outputStream.destroyed) {
|
|
@@ -51635,7 +52303,7 @@ async function runModels(sessionPath, opts = {}) {
|
|
|
51635
52303
|
opts.onStatusChange?.(id, statusCache.models[id]);
|
|
51636
52304
|
const stopped = await terminateChildTree(proc);
|
|
51637
52305
|
if (!stopped) {
|
|
51638
|
-
persistErrorLog(rt?.errorLogPath ??
|
|
52306
|
+
persistErrorLog(rt?.errorLogPath ?? join30(sessionPath, "errors", `${id}.log`), "TIMEOUT: child survived SIGKILL \u2014 it may still be running and billing", stderr, stdoutTail);
|
|
51639
52307
|
}
|
|
51640
52308
|
};
|
|
51641
52309
|
const allDone = Promise.all(completionPromises);
|
|
@@ -51694,23 +52362,23 @@ async function judgeResponses(sessionPath, opts = {}) {
|
|
|
51694
52362
|
const responses = {};
|
|
51695
52363
|
for (const file2 of responseFiles) {
|
|
51696
52364
|
const id = file2.replace(/^response-/, "").replace(/\.md$/, "");
|
|
51697
|
-
responses[id] =
|
|
52365
|
+
responses[id] = readFileSync20(join30(sessionPath, file2), "utf-8");
|
|
51698
52366
|
}
|
|
51699
|
-
const input =
|
|
52367
|
+
const input = readFileSync20(join30(sessionPath, "input.md"), "utf-8");
|
|
51700
52368
|
const judgePrompt = buildJudgePrompt(input, responses);
|
|
51701
|
-
|
|
52369
|
+
writeFileSync13(join30(sessionPath, "judge-prompt.md"), judgePrompt, "utf-8");
|
|
51702
52370
|
const judgeModels = opts.judges ?? getDefaultJudgeModels(sessionPath);
|
|
51703
|
-
const judgePath =
|
|
51704
|
-
|
|
52371
|
+
const judgePath = join30(sessionPath, "judging");
|
|
52372
|
+
mkdirSync13(judgePath, { recursive: true });
|
|
51705
52373
|
setupSession(judgePath, judgeModels, judgePrompt);
|
|
51706
52374
|
await runModels(judgePath, { claudeFlags: opts.claudeFlags });
|
|
51707
52375
|
const votes = parseJudgeVotes(judgePath, Object.keys(responses));
|
|
51708
52376
|
const verdict = aggregateVerdict(votes, Object.keys(responses));
|
|
51709
|
-
|
|
52377
|
+
writeFileSync13(join30(sessionPath, "verdict.md"), formatVerdict(verdict, sessionPath), "utf-8");
|
|
51710
52378
|
return verdict;
|
|
51711
52379
|
}
|
|
51712
52380
|
function getStatus(sessionPath) {
|
|
51713
|
-
return JSON.parse(
|
|
52381
|
+
return JSON.parse(readFileSync20(join30(sessionPath, "status.json"), "utf-8"));
|
|
51714
52382
|
}
|
|
51715
52383
|
function fisherYatesShuffle(arr) {
|
|
51716
52384
|
for (let i = arr.length - 1;i > 0; i--) {
|
|
@@ -51720,7 +52388,7 @@ function fisherYatesShuffle(arr) {
|
|
|
51720
52388
|
return arr;
|
|
51721
52389
|
}
|
|
51722
52390
|
function getDefaultJudgeModels(sessionPath) {
|
|
51723
|
-
const manifest = JSON.parse(
|
|
52391
|
+
const manifest = JSON.parse(readFileSync20(join30(sessionPath, "manifest.json"), "utf-8"));
|
|
51724
52392
|
return Object.values(manifest.models).map((e) => e.model);
|
|
51725
52393
|
}
|
|
51726
52394
|
function buildJudgePrompt(input, responses) {
|
|
@@ -51783,7 +52451,7 @@ function parseJudgeVotes(judgePath, responseIds) {
|
|
|
51783
52451
|
const judgeId = file2.replace(/^response-/, "").replace(/\.md$/, "");
|
|
51784
52452
|
let content;
|
|
51785
52453
|
try {
|
|
51786
|
-
content =
|
|
52454
|
+
content = readFileSync20(join30(judgePath, file2), "utf-8");
|
|
51787
52455
|
} catch {
|
|
51788
52456
|
continue;
|
|
51789
52457
|
}
|
|
@@ -51835,7 +52503,7 @@ function aggregateVerdict(votes, responseIds) {
|
|
|
51835
52503
|
function formatVerdict(verdict, sessionPath) {
|
|
51836
52504
|
let manifest = null;
|
|
51837
52505
|
try {
|
|
51838
|
-
manifest = JSON.parse(
|
|
52506
|
+
manifest = JSON.parse(readFileSync20(join30(sessionPath, "manifest.json"), "utf-8"));
|
|
51839
52507
|
} catch {}
|
|
51840
52508
|
let output = `# Team Verdict
|
|
51841
52509
|
|
|
@@ -51896,14 +52564,14 @@ __export(exports_mcp_server, {
|
|
|
51896
52564
|
parseAnthropicSse: () => parseAnthropicSse,
|
|
51897
52565
|
formatTeamResult: () => formatTeamResult
|
|
51898
52566
|
});
|
|
51899
|
-
import { existsSync as
|
|
51900
|
-
import { homedir as
|
|
51901
|
-
import { dirname as dirname9, join as
|
|
52567
|
+
import { existsSync as existsSync22, mkdirSync as mkdirSync14, readFileSync as readFileSync21, readdirSync as readdirSync4, writeFileSync as writeFileSync14 } from "fs";
|
|
52568
|
+
import { homedir as homedir29 } from "os";
|
|
52569
|
+
import { dirname as dirname9, join as join31, resolve as resolve4 } from "path";
|
|
51902
52570
|
import { fileURLToPath } from "url";
|
|
51903
52571
|
async function loadAllModels(forceRefresh = false) {
|
|
51904
|
-
if (!forceRefresh &&
|
|
52572
|
+
if (!forceRefresh && existsSync22(ALL_MODELS_CACHE_PATH2)) {
|
|
51905
52573
|
try {
|
|
51906
|
-
const cacheData = JSON.parse(
|
|
52574
|
+
const cacheData = JSON.parse(readFileSync21(ALL_MODELS_CACHE_PATH2, "utf-8"));
|
|
51907
52575
|
const lastUpdated = new Date(cacheData.lastUpdated);
|
|
51908
52576
|
const ageInDays = (Date.now() - lastUpdated.getTime()) / (1000 * 60 * 60 * 24);
|
|
51909
52577
|
if (ageInDays <= CACHE_MAX_AGE_DAYS) {
|
|
@@ -51917,12 +52585,12 @@ async function loadAllModels(forceRefresh = false) {
|
|
|
51917
52585
|
throw new Error(`API returned ${response.status}`);
|
|
51918
52586
|
const data = await response.json();
|
|
51919
52587
|
const models = data.data || [];
|
|
51920
|
-
|
|
51921
|
-
|
|
52588
|
+
mkdirSync14(CLAUDISH_CACHE_DIR, { recursive: true });
|
|
52589
|
+
writeFileSync14(ALL_MODELS_CACHE_PATH2, JSON.stringify({ lastUpdated: new Date().toISOString(), models }), "utf-8");
|
|
51922
52590
|
return models;
|
|
51923
52591
|
} catch {
|
|
51924
|
-
if (
|
|
51925
|
-
const cacheData = JSON.parse(
|
|
52592
|
+
if (existsSync22(ALL_MODELS_CACHE_PATH2)) {
|
|
52593
|
+
const cacheData = JSON.parse(readFileSync21(ALL_MODELS_CACHE_PATH2, "utf-8"));
|
|
51926
52594
|
return cacheData.models || [];
|
|
51927
52595
|
}
|
|
51928
52596
|
return [];
|
|
@@ -52523,7 +53191,7 @@ Use with: run_prompt(model="${results[0].model.id}", prompt="your prompt")`;
|
|
|
52523
53191
|
let stderrFull = stderr_snippet || "";
|
|
52524
53192
|
if (error_log_path) {
|
|
52525
53193
|
try {
|
|
52526
|
-
stderrFull =
|
|
53194
|
+
stderrFull = readFileSync21(error_log_path, "utf-8");
|
|
52527
53195
|
} catch {}
|
|
52528
53196
|
}
|
|
52529
53197
|
const sessionData = {};
|
|
@@ -52531,16 +53199,16 @@ Use with: run_prompt(model="${results[0].model.id}", prompt="your prompt")`;
|
|
|
52531
53199
|
const sp = session_path;
|
|
52532
53200
|
for (const file2 of ["status.json", "manifest.json", "input.md"]) {
|
|
52533
53201
|
try {
|
|
52534
|
-
sessionData[file2] =
|
|
53202
|
+
sessionData[file2] = readFileSync21(join31(sp, file2), "utf-8");
|
|
52535
53203
|
} catch {}
|
|
52536
53204
|
}
|
|
52537
53205
|
try {
|
|
52538
|
-
const errorDir =
|
|
52539
|
-
if (
|
|
53206
|
+
const errorDir = join31(sp, "errors");
|
|
53207
|
+
if (existsSync22(errorDir)) {
|
|
52540
53208
|
for (const f of readdirSync4(errorDir)) {
|
|
52541
53209
|
if (f.endsWith(".log")) {
|
|
52542
53210
|
try {
|
|
52543
|
-
sessionData[`errors/${f}`] =
|
|
53211
|
+
sessionData[`errors/${f}`] = readFileSync21(join31(errorDir, f), "utf-8");
|
|
52544
53212
|
} catch {}
|
|
52545
53213
|
}
|
|
52546
53214
|
}
|
|
@@ -52550,7 +53218,7 @@ Use with: run_prompt(model="${results[0].model.id}", prompt="your prompt")`;
|
|
|
52550
53218
|
for (const f of readdirSync4(sp)) {
|
|
52551
53219
|
if (f.startsWith("response-") && f.endsWith(".md")) {
|
|
52552
53220
|
try {
|
|
52553
|
-
const content =
|
|
53221
|
+
const content = readFileSync21(join31(sp, f), "utf-8");
|
|
52554
53222
|
sessionData[f] = content.slice(0, 200) + (content.length > 200 ? "... (truncated)" : "");
|
|
52555
53223
|
} catch {}
|
|
52556
53224
|
}
|
|
@@ -52559,9 +53227,9 @@ Use with: run_prompt(model="${results[0].model.id}", prompt="your prompt")`;
|
|
|
52559
53227
|
}
|
|
52560
53228
|
let version2 = "unknown";
|
|
52561
53229
|
try {
|
|
52562
|
-
const pkgPath =
|
|
52563
|
-
if (
|
|
52564
|
-
version2 = JSON.parse(
|
|
53230
|
+
const pkgPath = join31(__dirname2, "../package.json");
|
|
53231
|
+
if (existsSync22(pkgPath)) {
|
|
53232
|
+
version2 = JSON.parse(readFileSync21(pkgPath, "utf-8")).version;
|
|
52565
53233
|
}
|
|
52566
53234
|
} catch {}
|
|
52567
53235
|
const report = {
|
|
@@ -52976,8 +53644,8 @@ var init_mcp_server = __esm(() => {
|
|
|
52976
53644
|
import_dotenv2.config({ quiet: true });
|
|
52977
53645
|
__filename2 = fileURLToPath(import.meta.url);
|
|
52978
53646
|
__dirname2 = dirname9(__filename2);
|
|
52979
|
-
CLAUDISH_CACHE_DIR =
|
|
52980
|
-
ALL_MODELS_CACHE_PATH2 =
|
|
53647
|
+
CLAUDISH_CACHE_DIR = join31(homedir29(), ".claudish");
|
|
53648
|
+
ALL_MODELS_CACHE_PATH2 = join31(CLAUDISH_CACHE_DIR, "all-models.json");
|
|
52981
53649
|
NEXT_STEP = {
|
|
52982
53650
|
nonzero_exit: "read the evidence log, then retry or drop the model",
|
|
52983
53651
|
timeout: "raise `timeout`, or pick a faster model",
|
|
@@ -53003,7 +53671,7 @@ var exports_serve_command = {};
|
|
|
53003
53671
|
__export(exports_serve_command, {
|
|
53004
53672
|
serveCommand: () => serveCommand
|
|
53005
53673
|
});
|
|
53006
|
-
import { existsSync as
|
|
53674
|
+
import { existsSync as existsSync23, readFileSync as readFileSync22 } from "fs";
|
|
53007
53675
|
function parseServeArgs(args) {
|
|
53008
53676
|
const out = {};
|
|
53009
53677
|
for (let i = 0;i < args.length; i++) {
|
|
@@ -53022,12 +53690,12 @@ function parseServeArgs(args) {
|
|
|
53022
53690
|
return out;
|
|
53023
53691
|
}
|
|
53024
53692
|
function loadModelMap(path) {
|
|
53025
|
-
if (!
|
|
53693
|
+
if (!existsSync23(path)) {
|
|
53026
53694
|
throw new Error(`--models file not found: ${path}`);
|
|
53027
53695
|
}
|
|
53028
53696
|
let raw2;
|
|
53029
53697
|
try {
|
|
53030
|
-
raw2 =
|
|
53698
|
+
raw2 = readFileSync22(path, "utf-8");
|
|
53031
53699
|
} catch (e) {
|
|
53032
53700
|
throw new Error(`failed to read --models file ${path}: ${e instanceof Error ? e.message : String(e)}`);
|
|
53033
53701
|
}
|
|
@@ -53106,7 +53774,7 @@ var exports_behavior_command = {};
|
|
|
53106
53774
|
__export(exports_behavior_command, {
|
|
53107
53775
|
behaviorCommand: () => behaviorCommand
|
|
53108
53776
|
});
|
|
53109
|
-
import { existsSync as
|
|
53777
|
+
import { existsSync as existsSync24, readFileSync as readFileSync23, writeFileSync as writeFileSync15 } from "fs";
|
|
53110
53778
|
function severityColor(sev) {
|
|
53111
53779
|
if (sev === "fix")
|
|
53112
53780
|
return green(sev);
|
|
@@ -53204,8 +53872,8 @@ function setTelemetryEnabled(value) {
|
|
|
53204
53872
|
const path = getConfigPath();
|
|
53205
53873
|
let cfg = {};
|
|
53206
53874
|
try {
|
|
53207
|
-
if (
|
|
53208
|
-
const parsed = JSON.parse(
|
|
53875
|
+
if (existsSync24(path)) {
|
|
53876
|
+
const parsed = JSON.parse(readFileSync23(path, "utf-8"));
|
|
53209
53877
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
53210
53878
|
cfg = parsed;
|
|
53211
53879
|
}
|
|
@@ -53214,7 +53882,7 @@ function setTelemetryEnabled(value) {
|
|
|
53214
53882
|
const behavior = cfg.behavior && typeof cfg.behavior === "object" && !Array.isArray(cfg.behavior) ? { ...cfg.behavior } : {};
|
|
53215
53883
|
behavior.telemetry = { enabled: value };
|
|
53216
53884
|
cfg.behavior = behavior;
|
|
53217
|
-
|
|
53885
|
+
writeFileSync15(path, `${JSON.stringify(cfg, null, 2)}
|
|
53218
53886
|
`, "utf-8");
|
|
53219
53887
|
}
|
|
53220
53888
|
function showTelemetry(action, json2) {
|
|
@@ -53226,8 +53894,8 @@ function showTelemetry(action, json2) {
|
|
|
53226
53894
|
let pending = 0;
|
|
53227
53895
|
try {
|
|
53228
53896
|
const path = outboxPath();
|
|
53229
|
-
if (
|
|
53230
|
-
pending =
|
|
53897
|
+
if (existsSync24(path)) {
|
|
53898
|
+
pending = readFileSync23(path, "utf8").split(`
|
|
53231
53899
|
`).filter(Boolean).length;
|
|
53232
53900
|
}
|
|
53233
53901
|
} catch {}
|
|
@@ -53299,9 +53967,9 @@ __export(exports_team_grid, {
|
|
|
53299
53967
|
});
|
|
53300
53968
|
import { spawn as spawn3 } from "child_process";
|
|
53301
53969
|
import { execSync } from "child_process";
|
|
53302
|
-
import { existsSync as
|
|
53970
|
+
import { existsSync as existsSync25, readFileSync as readFileSync24, writeFileSync as writeFileSync16 } from "fs";
|
|
53303
53971
|
import { connect as netConnect } from "net";
|
|
53304
|
-
import { dirname as dirname10, join as
|
|
53972
|
+
import { dirname as dirname10, join as join32 } from "path";
|
|
53305
53973
|
import { setTimeout as wait } from "timers/promises";
|
|
53306
53974
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
53307
53975
|
function resolveRouteInfo(modelId) {
|
|
@@ -53395,18 +54063,18 @@ function buildPaneHeader(model, prompt, bg) {
|
|
|
53395
54063
|
function findMagmuxBinary() {
|
|
53396
54064
|
const thisFile = fileURLToPath2(import.meta.url);
|
|
53397
54065
|
const thisDir = dirname10(thisFile);
|
|
53398
|
-
const pkgRoot =
|
|
54066
|
+
const pkgRoot = join32(thisDir, "..");
|
|
53399
54067
|
const platform2 = process.platform;
|
|
53400
54068
|
const arch = process.arch;
|
|
53401
|
-
const bundledMagmux =
|
|
53402
|
-
if (
|
|
54069
|
+
const bundledMagmux = join32(pkgRoot, "native", `magmux-${platform2}-${arch}`);
|
|
54070
|
+
if (existsSync25(bundledMagmux))
|
|
53403
54071
|
return bundledMagmux;
|
|
53404
54072
|
try {
|
|
53405
54073
|
const pkgName = `@claudish/magmux-${platform2}-${arch}`;
|
|
53406
54074
|
let searchDir = pkgRoot;
|
|
53407
54075
|
for (let i = 0;i < 5; i++) {
|
|
53408
|
-
const candidate =
|
|
53409
|
-
if (
|
|
54076
|
+
const candidate = join32(searchDir, "node_modules", pkgName, "bin", "magmux");
|
|
54077
|
+
if (existsSync25(candidate))
|
|
53410
54078
|
return candidate;
|
|
53411
54079
|
const parent = dirname10(searchDir);
|
|
53412
54080
|
if (parent === searchDir)
|
|
@@ -53430,7 +54098,7 @@ function withoutControlPanes(evt) {
|
|
|
53430
54098
|
async function subscribeToMagmux(sockPath, onEvent) {
|
|
53431
54099
|
let client = null;
|
|
53432
54100
|
for (let attempt = 0;attempt < 40; attempt++) {
|
|
53433
|
-
if (
|
|
54101
|
+
if (existsSync25(sockPath)) {
|
|
53434
54102
|
try {
|
|
53435
54103
|
client = await new Promise((resolve5, reject) => {
|
|
53436
54104
|
const s = netConnect(sockPath);
|
|
@@ -53517,9 +54185,9 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
53517
54185
|
const keep = opts?.keep ?? false;
|
|
53518
54186
|
const manifest = setupSession(sessionPath, models, input);
|
|
53519
54187
|
const startedAt = new Date().toISOString();
|
|
53520
|
-
const gridfilePath =
|
|
53521
|
-
const prompt =
|
|
53522
|
-
const rawPrompt =
|
|
54188
|
+
const gridfilePath = join32(sessionPath, "gridfile.txt");
|
|
54189
|
+
const prompt = readFileSync24(join32(sessionPath, "input.md"), "utf-8").replace(/'/g, "'\\''").replace(/\n/g, " ");
|
|
54190
|
+
const rawPrompt = readFileSync24(join32(sessionPath, "input.md"), "utf-8");
|
|
53523
54191
|
const usedBannerColors = new Set;
|
|
53524
54192
|
const gridLines = Object.entries(manifest.models).map(([anonId]) => {
|
|
53525
54193
|
const model = manifest.models[anonId].model;
|
|
@@ -53530,7 +54198,7 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
53530
54198
|
const header = buildPaneHeader(model, rawPrompt, bg);
|
|
53531
54199
|
return `${header} claudish --model ${model} -y --quiet '${prompt}'`;
|
|
53532
54200
|
});
|
|
53533
|
-
|
|
54201
|
+
writeFileSync16(gridfilePath, `${gridLines.join(`
|
|
53534
54202
|
`)}
|
|
53535
54203
|
`, "utf-8");
|
|
53536
54204
|
const magmuxPath = findMagmuxBinary();
|
|
@@ -53550,8 +54218,8 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
53550
54218
|
});
|
|
53551
54219
|
const [{ results }] = await Promise.all([subscription, procExit]);
|
|
53552
54220
|
const status = buildTeamStatus(manifest, startedAt, results?.panes ?? null);
|
|
53553
|
-
const statusPath =
|
|
53554
|
-
|
|
54221
|
+
const statusPath = join32(sessionPath, "status.json");
|
|
54222
|
+
writeFileSync16(statusPath, JSON.stringify(status, null, 2), "utf-8");
|
|
53555
54223
|
return status;
|
|
53556
54224
|
}
|
|
53557
54225
|
var BANNER_BG_COLORS;
|
|
@@ -53575,8 +54243,8 @@ var exports_team_cli = {};
|
|
|
53575
54243
|
__export(exports_team_cli, {
|
|
53576
54244
|
teamCommand: () => teamCommand
|
|
53577
54245
|
});
|
|
53578
|
-
import { readFileSync as
|
|
53579
|
-
import { join as
|
|
54246
|
+
import { readFileSync as readFileSync25 } from "fs";
|
|
54247
|
+
import { join as join33 } from "path";
|
|
53580
54248
|
function getFlag(args, flag) {
|
|
53581
54249
|
const idx = args.indexOf(flag);
|
|
53582
54250
|
if (idx === -1 || idx + 1 >= args.length)
|
|
@@ -53699,7 +54367,7 @@ async function teamCommand(args) {
|
|
|
53699
54367
|
}
|
|
53700
54368
|
case "judge": {
|
|
53701
54369
|
await judgeResponses(sessionPath, { judges });
|
|
53702
|
-
console.log(
|
|
54370
|
+
console.log(readFileSync25(join33(sessionPath, "verdict.md"), "utf-8"));
|
|
53703
54371
|
break;
|
|
53704
54372
|
}
|
|
53705
54373
|
case "run-and-judge": {
|
|
@@ -53717,7 +54385,7 @@ async function teamCommand(args) {
|
|
|
53717
54385
|
});
|
|
53718
54386
|
printStatus(status);
|
|
53719
54387
|
await judgeResponses(sessionPath, { judges });
|
|
53720
|
-
console.log(
|
|
54388
|
+
console.log(readFileSync25(join33(sessionPath, "verdict.md"), "utf-8"));
|
|
53721
54389
|
break;
|
|
53722
54390
|
}
|
|
53723
54391
|
case "status": {
|
|
@@ -54809,7 +55477,7 @@ function wrapAnsi(string5, columns, options) {
|
|
|
54809
55477
|
return String(string5).normalize().replaceAll(`\r
|
|
54810
55478
|
`, `
|
|
54811
55479
|
`).split(`
|
|
54812
|
-
`).map((line) =>
|
|
55480
|
+
`).map((line) => exec5(line, columns, options)).join(`
|
|
54813
55481
|
`);
|
|
54814
55482
|
}
|
|
54815
55483
|
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 +55531,7 @@ var ESCAPES, END_CODE = 39, ANSI_ESCAPE_BELL = "\x07", ANSI_CSI = "[", ANSI_OSC
|
|
|
54863
55531
|
return string5;
|
|
54864
55532
|
}
|
|
54865
55533
|
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
54866
|
-
},
|
|
55534
|
+
}, exec5 = (string5, columns, options = {}) => {
|
|
54867
55535
|
if (options.trim !== false && string5.trim() === "") {
|
|
54868
55536
|
return "";
|
|
54869
55537
|
}
|
|
@@ -54965,7 +55633,7 @@ var init_wrap_ansi = __esm(() => {
|
|
|
54965
55633
|
function breakLines(content, width) {
|
|
54966
55634
|
return content.split(`
|
|
54967
55635
|
`).flatMap((line) => wrapAnsi(line, width, { trim: false, hard: true }).split(`
|
|
54968
|
-
`).map((
|
|
55636
|
+
`).map((str2) => str2.trimEnd())).join(`
|
|
54969
55637
|
`);
|
|
54970
55638
|
}
|
|
54971
55639
|
function readlineWidth() {
|
|
@@ -61511,12 +62179,12 @@ var require_bom_handling = __commonJS((exports) => {
|
|
|
61511
62179
|
this.encoder = encoder;
|
|
61512
62180
|
this.addBOM = true;
|
|
61513
62181
|
}
|
|
61514
|
-
PrependBOMWrapper.prototype.write = function(
|
|
62182
|
+
PrependBOMWrapper.prototype.write = function(str2) {
|
|
61515
62183
|
if (this.addBOM) {
|
|
61516
|
-
|
|
62184
|
+
str2 = BOMChar + str2;
|
|
61517
62185
|
this.addBOM = false;
|
|
61518
62186
|
}
|
|
61519
|
-
return this.encoder.write(
|
|
62187
|
+
return this.encoder.write(str2);
|
|
61520
62188
|
};
|
|
61521
62189
|
PrependBOMWrapper.prototype.end = function() {
|
|
61522
62190
|
return this.encoder.end();
|
|
@@ -61607,29 +62275,29 @@ var require_internal = __commonJS((exports, module) => {
|
|
|
61607
62275
|
function InternalEncoder(options, codec2) {
|
|
61608
62276
|
this.enc = codec2.enc;
|
|
61609
62277
|
}
|
|
61610
|
-
InternalEncoder.prototype.write = function(
|
|
61611
|
-
return Buffer2.from(
|
|
62278
|
+
InternalEncoder.prototype.write = function(str2) {
|
|
62279
|
+
return Buffer2.from(str2, this.enc);
|
|
61612
62280
|
};
|
|
61613
62281
|
InternalEncoder.prototype.end = function() {};
|
|
61614
62282
|
function InternalEncoderBase64(options, codec2) {
|
|
61615
62283
|
this.prevStr = "";
|
|
61616
62284
|
}
|
|
61617
|
-
InternalEncoderBase64.prototype.write = function(
|
|
61618
|
-
|
|
61619
|
-
var completeQuads =
|
|
61620
|
-
this.prevStr =
|
|
61621
|
-
|
|
61622
|
-
return Buffer2.from(
|
|
62285
|
+
InternalEncoderBase64.prototype.write = function(str2) {
|
|
62286
|
+
str2 = this.prevStr + str2;
|
|
62287
|
+
var completeQuads = str2.length - str2.length % 4;
|
|
62288
|
+
this.prevStr = str2.slice(completeQuads);
|
|
62289
|
+
str2 = str2.slice(0, completeQuads);
|
|
62290
|
+
return Buffer2.from(str2, "base64");
|
|
61623
62291
|
};
|
|
61624
62292
|
InternalEncoderBase64.prototype.end = function() {
|
|
61625
62293
|
return Buffer2.from(this.prevStr, "base64");
|
|
61626
62294
|
};
|
|
61627
62295
|
function InternalEncoderCesu8(options, codec2) {}
|
|
61628
|
-
InternalEncoderCesu8.prototype.write = function(
|
|
61629
|
-
var buf = Buffer2.alloc(
|
|
62296
|
+
InternalEncoderCesu8.prototype.write = function(str2) {
|
|
62297
|
+
var buf = Buffer2.alloc(str2.length * 3);
|
|
61630
62298
|
var bufIdx = 0;
|
|
61631
|
-
for (var i = 0;i <
|
|
61632
|
-
var charCode =
|
|
62299
|
+
for (var i = 0;i < str2.length; i++) {
|
|
62300
|
+
var charCode = str2.charCodeAt(i);
|
|
61633
62301
|
if (charCode < 128) {
|
|
61634
62302
|
buf[bufIdx++] = charCode;
|
|
61635
62303
|
} else if (charCode < 2048) {
|
|
@@ -61709,25 +62377,25 @@ var require_internal = __commonJS((exports, module) => {
|
|
|
61709
62377
|
function InternalEncoderUtf8(options, codec2) {
|
|
61710
62378
|
this.highSurrogate = "";
|
|
61711
62379
|
}
|
|
61712
|
-
InternalEncoderUtf8.prototype.write = function(
|
|
62380
|
+
InternalEncoderUtf8.prototype.write = function(str2) {
|
|
61713
62381
|
if (this.highSurrogate) {
|
|
61714
|
-
|
|
62382
|
+
str2 = this.highSurrogate + str2;
|
|
61715
62383
|
this.highSurrogate = "";
|
|
61716
62384
|
}
|
|
61717
|
-
if (
|
|
61718
|
-
var charCode =
|
|
62385
|
+
if (str2.length > 0) {
|
|
62386
|
+
var charCode = str2.charCodeAt(str2.length - 1);
|
|
61719
62387
|
if (charCode >= 55296 && charCode < 56320) {
|
|
61720
|
-
this.highSurrogate =
|
|
61721
|
-
|
|
62388
|
+
this.highSurrogate = str2[str2.length - 1];
|
|
62389
|
+
str2 = str2.slice(0, str2.length - 1);
|
|
61722
62390
|
}
|
|
61723
62391
|
}
|
|
61724
|
-
return Buffer2.from(
|
|
62392
|
+
return Buffer2.from(str2, this.enc);
|
|
61725
62393
|
};
|
|
61726
62394
|
InternalEncoderUtf8.prototype.end = function() {
|
|
61727
62395
|
if (this.highSurrogate) {
|
|
61728
|
-
var
|
|
62396
|
+
var str2 = this.highSurrogate;
|
|
61729
62397
|
this.highSurrogate = "";
|
|
61730
|
-
return Buffer2.from(
|
|
62398
|
+
return Buffer2.from(str2, this.enc);
|
|
61731
62399
|
}
|
|
61732
62400
|
};
|
|
61733
62401
|
});
|
|
@@ -61751,8 +62419,8 @@ var require_utf32 = __commonJS((exports) => {
|
|
|
61751
62419
|
this.isLE = codec2.isLE;
|
|
61752
62420
|
this.highSurrogate = 0;
|
|
61753
62421
|
}
|
|
61754
|
-
Utf32Encoder.prototype.write = function(
|
|
61755
|
-
var src = Buffer2.from(
|
|
62422
|
+
Utf32Encoder.prototype.write = function(str2) {
|
|
62423
|
+
var src = Buffer2.from(str2, "ucs2");
|
|
61756
62424
|
var dst = Buffer2.alloc(src.length * 2);
|
|
61757
62425
|
var write32 = this.isLE ? dst.writeUInt32LE : dst.writeUInt32BE;
|
|
61758
62426
|
var offset = 0;
|
|
@@ -61873,8 +62541,8 @@ var require_utf32 = __commonJS((exports) => {
|
|
|
61873
62541
|
}
|
|
61874
62542
|
this.encoder = codec2.iconv.getEncoder(options.defaultEncoding || "utf-32le", options);
|
|
61875
62543
|
}
|
|
61876
|
-
Utf32AutoEncoder.prototype.write = function(
|
|
61877
|
-
return this.encoder.write(
|
|
62544
|
+
Utf32AutoEncoder.prototype.write = function(str2) {
|
|
62545
|
+
return this.encoder.write(str2);
|
|
61878
62546
|
};
|
|
61879
62547
|
Utf32AutoEncoder.prototype.end = function() {
|
|
61880
62548
|
return this.encoder.end();
|
|
@@ -61975,8 +62643,8 @@ var require_utf16 = __commonJS((exports) => {
|
|
|
61975
62643
|
Utf16BECodec.prototype.decoder = Utf16BEDecoder;
|
|
61976
62644
|
Utf16BECodec.prototype.bomAware = true;
|
|
61977
62645
|
function Utf16BEEncoder() {}
|
|
61978
|
-
Utf16BEEncoder.prototype.write = function(
|
|
61979
|
-
var buf = Buffer2.from(
|
|
62646
|
+
Utf16BEEncoder.prototype.write = function(str2) {
|
|
62647
|
+
var buf = Buffer2.from(str2, "ucs2");
|
|
61980
62648
|
for (var i = 0;i < buf.length; i += 2) {
|
|
61981
62649
|
var tmp = buf[i];
|
|
61982
62650
|
buf[i] = buf[i + 1];
|
|
@@ -62024,8 +62692,8 @@ var require_utf16 = __commonJS((exports) => {
|
|
|
62024
62692
|
}
|
|
62025
62693
|
this.encoder = codec2.iconv.getEncoder("utf-16le", options);
|
|
62026
62694
|
}
|
|
62027
|
-
Utf16Encoder.prototype.write = function(
|
|
62028
|
-
return this.encoder.write(
|
|
62695
|
+
Utf16Encoder.prototype.write = function(str2) {
|
|
62696
|
+
return this.encoder.write(str2);
|
|
62029
62697
|
};
|
|
62030
62698
|
Utf16Encoder.prototype.end = function() {
|
|
62031
62699
|
return this.encoder.end();
|
|
@@ -62124,8 +62792,8 @@ var require_utf7 = __commonJS((exports) => {
|
|
|
62124
62792
|
function Utf7Encoder(options, codec2) {
|
|
62125
62793
|
this.iconv = codec2.iconv;
|
|
62126
62794
|
}
|
|
62127
|
-
Utf7Encoder.prototype.write = function(
|
|
62128
|
-
return Buffer2.from(
|
|
62795
|
+
Utf7Encoder.prototype.write = function(str2) {
|
|
62796
|
+
return Buffer2.from(str2.replace(nonDirectChars, function(chunk) {
|
|
62129
62797
|
return "+" + (chunk === "+" ? "" : this.iconv.encode(chunk, "utf16-be").toString("base64").replace(/=+$/, "")) + "-";
|
|
62130
62798
|
}.bind(this)));
|
|
62131
62799
|
};
|
|
@@ -62208,14 +62876,14 @@ var require_utf7 = __commonJS((exports) => {
|
|
|
62208
62876
|
this.base64Accum = Buffer2.alloc(6);
|
|
62209
62877
|
this.base64AccumIdx = 0;
|
|
62210
62878
|
}
|
|
62211
|
-
Utf7IMAPEncoder.prototype.write = function(
|
|
62879
|
+
Utf7IMAPEncoder.prototype.write = function(str2) {
|
|
62212
62880
|
var inBase64 = this.inBase64;
|
|
62213
62881
|
var base64Accum = this.base64Accum;
|
|
62214
62882
|
var base64AccumIdx = this.base64AccumIdx;
|
|
62215
|
-
var buf = Buffer2.alloc(
|
|
62883
|
+
var buf = Buffer2.alloc(str2.length * 5 + 10);
|
|
62216
62884
|
var bufIdx = 0;
|
|
62217
|
-
for (var i2 = 0;i2 <
|
|
62218
|
-
var uChar =
|
|
62885
|
+
for (var i2 = 0;i2 < str2.length; i2++) {
|
|
62886
|
+
var uChar = str2.charCodeAt(i2);
|
|
62219
62887
|
if (uChar >= 32 && uChar <= 126) {
|
|
62220
62888
|
if (inBase64) {
|
|
62221
62889
|
if (base64AccumIdx > 0) {
|
|
@@ -62353,10 +63021,10 @@ var require_sbcs_codec = __commonJS((exports) => {
|
|
|
62353
63021
|
function SBCSEncoder(options, codec2) {
|
|
62354
63022
|
this.encodeBuf = codec2.encodeBuf;
|
|
62355
63023
|
}
|
|
62356
|
-
SBCSEncoder.prototype.write = function(
|
|
62357
|
-
var buf = Buffer2.alloc(
|
|
62358
|
-
for (var i = 0;i <
|
|
62359
|
-
buf[i] = this.encodeBuf[
|
|
63024
|
+
SBCSEncoder.prototype.write = function(str2) {
|
|
63025
|
+
var buf = Buffer2.alloc(str2.length);
|
|
63026
|
+
for (var i = 0;i < str2.length; i++) {
|
|
63027
|
+
buf[i] = this.encodeBuf[str2.charCodeAt(i)];
|
|
62360
63028
|
}
|
|
62361
63029
|
return buf;
|
|
62362
63030
|
};
|
|
@@ -63225,8 +63893,8 @@ var require_dbcs_codec = __commonJS((exports) => {
|
|
|
63225
63893
|
this.defaultCharSingleByte = codec2.defCharSB;
|
|
63226
63894
|
this.gb18030 = codec2.gb18030;
|
|
63227
63895
|
}
|
|
63228
|
-
DBCSEncoder.prototype.write = function(
|
|
63229
|
-
var newBuf = Buffer2.alloc(
|
|
63896
|
+
DBCSEncoder.prototype.write = function(str2) {
|
|
63897
|
+
var newBuf = Buffer2.alloc(str2.length * (this.gb18030 ? 4 : 3));
|
|
63230
63898
|
var leadSurrogate = this.leadSurrogate;
|
|
63231
63899
|
var seqObj = this.seqObj;
|
|
63232
63900
|
var nextChar = -1;
|
|
@@ -63234,9 +63902,9 @@ var require_dbcs_codec = __commonJS((exports) => {
|
|
|
63234
63902
|
var j = 0;
|
|
63235
63903
|
while (true) {
|
|
63236
63904
|
if (nextChar === -1) {
|
|
63237
|
-
if (i2 ==
|
|
63905
|
+
if (i2 == str2.length)
|
|
63238
63906
|
break;
|
|
63239
|
-
var uCode =
|
|
63907
|
+
var uCode = str2.charCodeAt(i2++);
|
|
63240
63908
|
} else {
|
|
63241
63909
|
var uCode = nextChar;
|
|
63242
63910
|
nextChar = -1;
|
|
@@ -64975,10 +65643,10 @@ var require_lib3 = __commonJS((exports, module) => {
|
|
|
64975
65643
|
iconv.encodings = null;
|
|
64976
65644
|
iconv.defaultCharUnicode = "\uFFFD";
|
|
64977
65645
|
iconv.defaultCharSingleByte = "?";
|
|
64978
|
-
iconv.encode = function encode3(
|
|
64979
|
-
|
|
65646
|
+
iconv.encode = function encode3(str2, encoding, options) {
|
|
65647
|
+
str2 = "" + (str2 || "");
|
|
64980
65648
|
var encoder = iconv.getEncoder(encoding, options);
|
|
64981
|
-
var res = encoder.write(
|
|
65649
|
+
var res = encoder.write(str2);
|
|
64982
65650
|
var trail = encoder.end();
|
|
64983
65651
|
return trail && trail.length > 0 ? Buffer2.concat([res, trail]) : res;
|
|
64984
65652
|
};
|
|
@@ -65143,7 +65811,7 @@ var init_RemoveFileError = __esm(() => {
|
|
|
65143
65811
|
|
|
65144
65812
|
// ../../node_modules/.bun/@inquirer+external-editor@2.0.1+04f2146be16c61ef/node_modules/@inquirer/external-editor/dist/index.js
|
|
65145
65813
|
import { spawn as spawn4, spawnSync as spawnSync2 } from "child_process";
|
|
65146
|
-
import { readFileSync as
|
|
65814
|
+
import { readFileSync as readFileSync26, unlinkSync as unlinkSync6, writeFileSync as writeFileSync17 } from "fs";
|
|
65147
65815
|
import path from "path";
|
|
65148
65816
|
import os from "os";
|
|
65149
65817
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
@@ -65167,12 +65835,12 @@ function sanitizeAffix(affix) {
|
|
|
65167
65835
|
return "";
|
|
65168
65836
|
return affix.replace(/[^a-zA-Z0-9_.-]/g, "_");
|
|
65169
65837
|
}
|
|
65170
|
-
function splitStringBySpace(
|
|
65838
|
+
function splitStringBySpace(str2) {
|
|
65171
65839
|
const pieces = [];
|
|
65172
65840
|
let currentString = "";
|
|
65173
|
-
for (let strIndex = 0;strIndex <
|
|
65174
|
-
const currentLetter =
|
|
65175
|
-
if (strIndex > 0 && currentLetter === " " &&
|
|
65841
|
+
for (let strIndex = 0;strIndex < str2.length; strIndex++) {
|
|
65842
|
+
const currentLetter = str2.charAt(strIndex);
|
|
65843
|
+
if (strIndex > 0 && currentLetter === " " && str2[strIndex - 1] !== "\\" && currentString.length > 0) {
|
|
65176
65844
|
pieces.push(currentString);
|
|
65177
65845
|
currentString = "";
|
|
65178
65846
|
} else {
|
|
@@ -65252,14 +65920,14 @@ class ExternalEditor {
|
|
|
65252
65920
|
if (Object.prototype.hasOwnProperty.call(this.fileOptions, "mode")) {
|
|
65253
65921
|
opt.mode = this.fileOptions.mode;
|
|
65254
65922
|
}
|
|
65255
|
-
|
|
65923
|
+
writeFileSync17(this.tempFile, this.text, opt);
|
|
65256
65924
|
} catch (createFileError) {
|
|
65257
65925
|
throw new CreateFileError(createFileError);
|
|
65258
65926
|
}
|
|
65259
65927
|
}
|
|
65260
65928
|
readTemporaryFile() {
|
|
65261
65929
|
try {
|
|
65262
|
-
const tempFileBuffer =
|
|
65930
|
+
const tempFileBuffer = readFileSync26(this.tempFile);
|
|
65263
65931
|
if (tempFileBuffer.length === 0) {
|
|
65264
65932
|
this.text = "";
|
|
65265
65933
|
} else {
|
|
@@ -65275,7 +65943,7 @@ class ExternalEditor {
|
|
|
65275
65943
|
}
|
|
65276
65944
|
removeTemporaryFile() {
|
|
65277
65945
|
try {
|
|
65278
|
-
|
|
65946
|
+
unlinkSync6(this.tempFile);
|
|
65279
65947
|
} catch (removeFileError) {
|
|
65280
65948
|
throw new RemoveFileError(removeFileError);
|
|
65281
65949
|
}
|
|
@@ -66240,9 +66908,9 @@ var init_dist16 = __esm(() => {
|
|
|
66240
66908
|
|
|
66241
66909
|
// src/auth/antigravity-oauth.ts
|
|
66242
66910
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
66243
|
-
import { existsSync as
|
|
66244
|
-
import { homedir as
|
|
66245
|
-
import { join as
|
|
66911
|
+
import { existsSync as existsSync26, unlinkSync as unlinkSync7 } from "fs";
|
|
66912
|
+
import { homedir as homedir30 } from "os";
|
|
66913
|
+
import { join as join34 } from "path";
|
|
66246
66914
|
async function defaultSuggestModel() {
|
|
66247
66915
|
try {
|
|
66248
66916
|
const tok = readSharedAntigravityToken();
|
|
@@ -66363,9 +67031,9 @@ No session detected yet. Starting the Antigravity CLI interactively \u2014
|
|
|
66363
67031
|
async logout(deps) {
|
|
66364
67032
|
deleteSharedAntigravityToken(deps);
|
|
66365
67033
|
try {
|
|
66366
|
-
const tokenFile =
|
|
66367
|
-
if (
|
|
66368
|
-
|
|
67034
|
+
const tokenFile = join34(homedir30(), ".gemini", "antigravity-cli", "antigravity-oauth-token");
|
|
67035
|
+
if (existsSync26(tokenFile))
|
|
67036
|
+
unlinkSync7(tokenFile);
|
|
66369
67037
|
} catch {}
|
|
66370
67038
|
log("[AntigravityOAuth] Antigravity session cleared (keychain + agy token file)");
|
|
66371
67039
|
}
|
|
@@ -66463,6 +67131,7 @@ var init_auth_commands = __esm(() => {
|
|
|
66463
67131
|
init_antigravity_oauth();
|
|
66464
67132
|
init_antigravity_token();
|
|
66465
67133
|
init_codex_oauth();
|
|
67134
|
+
init_grok_oauth();
|
|
66466
67135
|
init_kimi_oauth();
|
|
66467
67136
|
init_oauth_registry();
|
|
66468
67137
|
AUTH_PROVIDERS = [
|
|
@@ -66486,6 +67155,13 @@ var init_auth_commands = __esm(() => {
|
|
|
66486
67155
|
prefix: "cx@",
|
|
66487
67156
|
getInstance: () => CodexOAuth.getInstance(),
|
|
66488
67157
|
registryKeys: ["openai-codex"]
|
|
67158
|
+
},
|
|
67159
|
+
{
|
|
67160
|
+
name: "grok",
|
|
67161
|
+
displayName: "Grok Build (SuperGrok / X Premium+)",
|
|
67162
|
+
prefix: "gk@",
|
|
67163
|
+
getInstance: () => GrokOAuth.getInstance(),
|
|
67164
|
+
registryKeys: ["grok-subscription"]
|
|
66489
67165
|
}
|
|
66490
67166
|
];
|
|
66491
67167
|
});
|
|
@@ -68230,9 +68906,9 @@ function timelineBarCells(totalMs, maxTotalMs, barWidth) {
|
|
|
68230
68906
|
function splitStageCells(ttfbMs, ttftMs, totalMs, barCells) {
|
|
68231
68907
|
const net = Math.max(0, ttfbMs);
|
|
68232
68908
|
const srv = Math.max(0, ttftMs - ttfbMs);
|
|
68233
|
-
const
|
|
68234
|
-
const durations = [net, srv,
|
|
68235
|
-
const sum = net + srv +
|
|
68909
|
+
const str2 = Math.max(0, totalMs - ttftMs);
|
|
68910
|
+
const durations = [net, srv, str2];
|
|
68911
|
+
const sum = net + srv + str2;
|
|
68236
68912
|
if (barCells <= 0)
|
|
68237
68913
|
return { network: 0, server: 0, streaming: 0 };
|
|
68238
68914
|
if (sum <= 0) {
|
|
@@ -68841,11 +69517,11 @@ function renderCard(result, isLiveProbe, w, width, scales, directKeyVar) {
|
|
|
68841
69517
|
function renderLegend(w) {
|
|
68842
69518
|
const net = STAGE_BG_ANSI.network;
|
|
68843
69519
|
const srv = STAGE_BG_ANSI.server;
|
|
68844
|
-
const
|
|
69520
|
+
const str2 = STAGE_BG_ANSI.streaming;
|
|
68845
69521
|
const netFg = hexToAnsiFg(STAGE_FG.network);
|
|
68846
69522
|
const srvFg = hexToAnsiFg(STAGE_FG.server);
|
|
68847
69523
|
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} ` + `${
|
|
69524
|
+
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
69525
|
`);
|
|
68850
69526
|
w(` ${pc.dim}bar length = total time, shared scale (slowest = full bar) \xB7 ` + `tok/s scaled to fastest${pc.reset}
|
|
68851
69527
|
`);
|
|
@@ -70481,22 +71157,22 @@ __export(exports_cli, {
|
|
|
70481
71157
|
});
|
|
70482
71158
|
import {
|
|
70483
71159
|
copyFileSync as copyFileSync2,
|
|
70484
|
-
existsSync as
|
|
70485
|
-
mkdirSync as
|
|
70486
|
-
readFileSync as
|
|
71160
|
+
existsSync as existsSync27,
|
|
71161
|
+
mkdirSync as mkdirSync15,
|
|
71162
|
+
readFileSync as readFileSync27,
|
|
70487
71163
|
readdirSync as readdirSync5,
|
|
70488
|
-
unlinkSync as
|
|
70489
|
-
writeFileSync as
|
|
71164
|
+
unlinkSync as unlinkSync8,
|
|
71165
|
+
writeFileSync as writeFileSync18
|
|
70490
71166
|
} from "fs";
|
|
70491
|
-
import { homedir as
|
|
70492
|
-
import { dirname as dirname11, join as
|
|
71167
|
+
import { homedir as homedir31 } from "os";
|
|
71168
|
+
import { dirname as dirname11, join as join35 } from "path";
|
|
70493
71169
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
70494
71170
|
function getVersion3() {
|
|
70495
71171
|
return VERSION;
|
|
70496
71172
|
}
|
|
70497
71173
|
function clearAllModelCaches() {
|
|
70498
|
-
const cacheDir =
|
|
70499
|
-
if (!
|
|
71174
|
+
const cacheDir = join35(homedir31(), ".claudish");
|
|
71175
|
+
if (!existsSync27(cacheDir))
|
|
70500
71176
|
return;
|
|
70501
71177
|
const cachePatterns = ["pricing-cache.json", "recommended-models-cache.json"];
|
|
70502
71178
|
let cleared = 0;
|
|
@@ -70504,7 +71180,7 @@ function clearAllModelCaches() {
|
|
|
70504
71180
|
const files = readdirSync5(cacheDir);
|
|
70505
71181
|
for (const file2 of files) {
|
|
70506
71182
|
if (cachePatterns.includes(file2)) {
|
|
70507
|
-
|
|
71183
|
+
unlinkSync8(join35(cacheDir, file2));
|
|
70508
71184
|
cleared++;
|
|
70509
71185
|
}
|
|
70510
71186
|
}
|
|
@@ -70920,15 +71596,15 @@ Usage: claudish --models --provider <slug>`);
|
|
|
70920
71596
|
});
|
|
70921
71597
|
config3.resolvedDefaultProvider = resolved;
|
|
70922
71598
|
if (resolved.legacyAutoPromoted && !config3.quiet) {
|
|
70923
|
-
const markerFile =
|
|
70924
|
-
if (!
|
|
71599
|
+
const markerFile = join35(homedir31(), ".claudish", ".legacy-litellm-hint-shown");
|
|
71600
|
+
if (!existsSync27(markerFile)) {
|
|
70925
71601
|
const hint = buildLegacyHint(resolved);
|
|
70926
71602
|
if (hint) {
|
|
70927
71603
|
console.error(hint);
|
|
70928
71604
|
}
|
|
70929
71605
|
try {
|
|
70930
|
-
|
|
70931
|
-
|
|
71606
|
+
mkdirSync15(dirname11(markerFile), { recursive: true });
|
|
71607
|
+
writeFileSync18(markerFile, new Date().toISOString(), "utf-8");
|
|
70932
71608
|
} catch {}
|
|
70933
71609
|
}
|
|
70934
71610
|
}
|
|
@@ -71998,8 +72674,8 @@ ${h("MORE INFO")}
|
|
|
71998
72674
|
}
|
|
71999
72675
|
function printAIAgentGuide() {
|
|
72000
72676
|
try {
|
|
72001
|
-
const guidePath =
|
|
72002
|
-
const guideContent =
|
|
72677
|
+
const guidePath = join35(__dirname3, "../AI_AGENT_GUIDE.md");
|
|
72678
|
+
const guideContent = readFileSync27(guidePath, "utf-8");
|
|
72003
72679
|
console.log(guideContent);
|
|
72004
72680
|
} catch (error46) {
|
|
72005
72681
|
console.error("Error reading AI Agent Guide:");
|
|
@@ -72015,19 +72691,19 @@ async function initializeClaudishSkill() {
|
|
|
72015
72691
|
console.log(`\uD83D\uDD27 Initializing Claudish skill in current project...
|
|
72016
72692
|
`);
|
|
72017
72693
|
const cwd = process.cwd();
|
|
72018
|
-
const claudeDir =
|
|
72019
|
-
const skillsDir =
|
|
72020
|
-
const claudishSkillDir =
|
|
72021
|
-
const skillFile =
|
|
72022
|
-
if (
|
|
72694
|
+
const claudeDir = join35(cwd, ".claude");
|
|
72695
|
+
const skillsDir = join35(claudeDir, "skills");
|
|
72696
|
+
const claudishSkillDir = join35(skillsDir, "claudish-usage");
|
|
72697
|
+
const skillFile = join35(claudishSkillDir, "SKILL.md");
|
|
72698
|
+
if (existsSync27(skillFile)) {
|
|
72023
72699
|
console.log("\u2705 Claudish skill already installed at:");
|
|
72024
72700
|
console.log(` ${skillFile}
|
|
72025
72701
|
`);
|
|
72026
72702
|
console.log("\uD83D\uDCA1 To reinstall, delete the file and run 'claudish --init' again.");
|
|
72027
72703
|
return;
|
|
72028
72704
|
}
|
|
72029
|
-
const sourceSkillPath =
|
|
72030
|
-
if (!
|
|
72705
|
+
const sourceSkillPath = join35(__dirname3, "../skills/claudish-usage/SKILL.md");
|
|
72706
|
+
if (!existsSync27(sourceSkillPath)) {
|
|
72031
72707
|
console.error("\u274C Error: Claudish skill file not found in installation.");
|
|
72032
72708
|
console.error(` Expected at: ${sourceSkillPath}`);
|
|
72033
72709
|
console.error(`
|
|
@@ -72036,16 +72712,16 @@ async function initializeClaudishSkill() {
|
|
|
72036
72712
|
process.exit(1);
|
|
72037
72713
|
}
|
|
72038
72714
|
try {
|
|
72039
|
-
if (!
|
|
72040
|
-
|
|
72715
|
+
if (!existsSync27(claudeDir)) {
|
|
72716
|
+
mkdirSync15(claudeDir, { recursive: true });
|
|
72041
72717
|
console.log("\uD83D\uDCC1 Created .claude/ directory");
|
|
72042
72718
|
}
|
|
72043
|
-
if (!
|
|
72044
|
-
|
|
72719
|
+
if (!existsSync27(skillsDir)) {
|
|
72720
|
+
mkdirSync15(skillsDir, { recursive: true });
|
|
72045
72721
|
console.log("\uD83D\uDCC1 Created .claude/skills/ directory");
|
|
72046
72722
|
}
|
|
72047
|
-
if (!
|
|
72048
|
-
|
|
72723
|
+
if (!existsSync27(claudishSkillDir)) {
|
|
72724
|
+
mkdirSync15(claudishSkillDir, { recursive: true });
|
|
72049
72725
|
console.log("\uD83D\uDCC1 Created .claude/skills/claudish-usage/ directory");
|
|
72050
72726
|
}
|
|
72051
72727
|
copyFileSync2(sourceSkillPath, skillFile);
|
|
@@ -72130,33 +72806,33 @@ __export(exports_update_checker, {
|
|
|
72130
72806
|
clearCache: () => clearCache,
|
|
72131
72807
|
checkForUpdates: () => checkForUpdates
|
|
72132
72808
|
});
|
|
72133
|
-
import { existsSync as
|
|
72134
|
-
import { homedir as
|
|
72135
|
-
import { join as
|
|
72809
|
+
import { existsSync as existsSync28, mkdirSync as mkdirSync16, readFileSync as readFileSync28, unlinkSync as unlinkSync9, writeFileSync as writeFileSync19 } from "fs";
|
|
72810
|
+
import { homedir as homedir32, platform as platform2, tmpdir } from "os";
|
|
72811
|
+
import { join as join36 } from "path";
|
|
72136
72812
|
function getCacheFilePath() {
|
|
72137
72813
|
let cacheDir;
|
|
72138
72814
|
if (isWindows) {
|
|
72139
|
-
const localAppData = process.env.LOCALAPPDATA ||
|
|
72140
|
-
cacheDir =
|
|
72815
|
+
const localAppData = process.env.LOCALAPPDATA || join36(homedir32(), "AppData", "Local");
|
|
72816
|
+
cacheDir = join36(localAppData, "claudish");
|
|
72141
72817
|
} else {
|
|
72142
|
-
cacheDir =
|
|
72818
|
+
cacheDir = join36(homedir32(), ".cache", "claudish");
|
|
72143
72819
|
}
|
|
72144
72820
|
try {
|
|
72145
|
-
if (!
|
|
72146
|
-
|
|
72821
|
+
if (!existsSync28(cacheDir)) {
|
|
72822
|
+
mkdirSync16(cacheDir, { recursive: true });
|
|
72147
72823
|
}
|
|
72148
|
-
return
|
|
72824
|
+
return join36(cacheDir, "update-check.json");
|
|
72149
72825
|
} catch {
|
|
72150
|
-
return
|
|
72826
|
+
return join36(tmpdir(), "claudish-update-check.json");
|
|
72151
72827
|
}
|
|
72152
72828
|
}
|
|
72153
72829
|
function readCache() {
|
|
72154
72830
|
try {
|
|
72155
72831
|
const cachePath = getCacheFilePath();
|
|
72156
|
-
if (!
|
|
72832
|
+
if (!existsSync28(cachePath)) {
|
|
72157
72833
|
return null;
|
|
72158
72834
|
}
|
|
72159
|
-
const data = JSON.parse(
|
|
72835
|
+
const data = JSON.parse(readFileSync28(cachePath, "utf-8"));
|
|
72160
72836
|
return data;
|
|
72161
72837
|
} catch {
|
|
72162
72838
|
return null;
|
|
@@ -72169,7 +72845,7 @@ function writeCache(latestVersion) {
|
|
|
72169
72845
|
lastCheck: Date.now(),
|
|
72170
72846
|
latestVersion
|
|
72171
72847
|
};
|
|
72172
|
-
|
|
72848
|
+
writeFileSync19(cachePath, JSON.stringify(data), "utf-8");
|
|
72173
72849
|
} catch {}
|
|
72174
72850
|
}
|
|
72175
72851
|
function isCacheValid(cache2) {
|
|
@@ -72179,8 +72855,8 @@ function isCacheValid(cache2) {
|
|
|
72179
72855
|
function clearCache() {
|
|
72180
72856
|
try {
|
|
72181
72857
|
const cachePath = getCacheFilePath();
|
|
72182
|
-
if (
|
|
72183
|
-
|
|
72858
|
+
if (existsSync28(cachePath)) {
|
|
72859
|
+
unlinkSync9(cachePath);
|
|
72184
72860
|
}
|
|
72185
72861
|
} catch {}
|
|
72186
72862
|
}
|
|
@@ -73064,15 +73740,15 @@ var init_local_liveness = __esm(() => {
|
|
|
73064
73740
|
});
|
|
73065
73741
|
|
|
73066
73742
|
// src/providers/probe-catalog.ts
|
|
73067
|
-
import { existsSync as
|
|
73068
|
-
import { homedir as
|
|
73069
|
-
import { dirname as dirname12, join as
|
|
73743
|
+
import { existsSync as existsSync29, mkdirSync as mkdirSync17, readFileSync as readFileSync29, writeFileSync as writeFileSync20 } from "fs";
|
|
73744
|
+
import { homedir as homedir33 } from "os";
|
|
73745
|
+
import { dirname as dirname12, join as join37 } from "path";
|
|
73070
73746
|
function readProbeModelsCache(path2 = PROBE_MODELS_CACHE_PATH) {
|
|
73071
|
-
if (!
|
|
73747
|
+
if (!existsSync29(path2))
|
|
73072
73748
|
return null;
|
|
73073
73749
|
let raw2;
|
|
73074
73750
|
try {
|
|
73075
|
-
raw2 = JSON.parse(
|
|
73751
|
+
raw2 = JSON.parse(readFileSync29(path2, "utf-8"));
|
|
73076
73752
|
} catch {
|
|
73077
73753
|
return null;
|
|
73078
73754
|
}
|
|
@@ -73081,8 +73757,8 @@ function readProbeModelsCache(path2 = PROBE_MODELS_CACHE_PATH) {
|
|
|
73081
73757
|
return raw2;
|
|
73082
73758
|
}
|
|
73083
73759
|
function writeProbeModelsCache(data, path2 = PROBE_MODELS_CACHE_PATH) {
|
|
73084
|
-
|
|
73085
|
-
|
|
73760
|
+
mkdirSync17(dirname12(path2), { recursive: true });
|
|
73761
|
+
writeFileSync20(path2, JSON.stringify(data), "utf-8");
|
|
73086
73762
|
}
|
|
73087
73763
|
function isCacheFresh(data, ttlMs = CACHE_TTL_MS4) {
|
|
73088
73764
|
if (!data?.generatedAt)
|
|
@@ -73201,7 +73877,7 @@ function isValidResponse(raw2) {
|
|
|
73201
73877
|
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
73878
|
var init_probe_catalog = __esm(() => {
|
|
73203
73879
|
CACHE_TTL_MS4 = 60 * 60 * 1000;
|
|
73204
|
-
PROBE_MODELS_CACHE_PATH =
|
|
73880
|
+
PROBE_MODELS_CACHE_PATH = join37(homedir33(), ".claudish", "probe-models.json");
|
|
73205
73881
|
});
|
|
73206
73882
|
|
|
73207
73883
|
// src/tui/constants.ts
|
|
@@ -79554,18 +80230,18 @@ __export(exports_claude_runner, {
|
|
|
79554
80230
|
});
|
|
79555
80231
|
import { spawn as spawn5 } from "child_process";
|
|
79556
80232
|
import {
|
|
79557
|
-
closeSync as
|
|
79558
|
-
existsSync as
|
|
79559
|
-
mkdirSync as
|
|
79560
|
-
openSync as
|
|
79561
|
-
readFileSync as
|
|
80233
|
+
closeSync as closeSync5,
|
|
80234
|
+
existsSync as existsSync30,
|
|
80235
|
+
mkdirSync as mkdirSync18,
|
|
80236
|
+
openSync as openSync5,
|
|
80237
|
+
readFileSync as readFileSync30,
|
|
79562
80238
|
readdirSync as readdirSync6,
|
|
79563
80239
|
statSync as statSync5,
|
|
79564
|
-
unlinkSync as
|
|
79565
|
-
writeFileSync as
|
|
80240
|
+
unlinkSync as unlinkSync10,
|
|
80241
|
+
writeFileSync as writeFileSync21
|
|
79566
80242
|
} from "fs";
|
|
79567
|
-
import { homedir as
|
|
79568
|
-
import { dirname as dirname13, join as
|
|
80243
|
+
import { homedir as homedir34, tmpdir as tmpdir2 } from "os";
|
|
80244
|
+
import { dirname as dirname13, join as join38 } from "path";
|
|
79569
80245
|
import { isatty } from "tty";
|
|
79570
80246
|
function releaseTerminalIsolation() {
|
|
79571
80247
|
if (!restoreTerminal)
|
|
@@ -79600,14 +80276,14 @@ function isProxyAuthMode(config3) {
|
|
|
79600
80276
|
}
|
|
79601
80277
|
function managedSettingsPath() {
|
|
79602
80278
|
if (isWindows2()) {
|
|
79603
|
-
return
|
|
80279
|
+
return join38(process.env.PROGRAMDATA || "C:\\ProgramData", "ClaudeCode", "managed-settings.json");
|
|
79604
80280
|
}
|
|
79605
80281
|
if (process.platform === "darwin") {
|
|
79606
80282
|
return "/Library/Application Support/ClaudeCode/managed-settings.json";
|
|
79607
80283
|
}
|
|
79608
80284
|
return "/etc/claude-code/managed-settings.json";
|
|
79609
80285
|
}
|
|
79610
|
-
function managedSettingsForcesClaudeAi(readFile3 =
|
|
80286
|
+
function managedSettingsForcesClaudeAi(readFile3 = readFileSync30) {
|
|
79611
80287
|
try {
|
|
79612
80288
|
const raw2 = readFile3(managedSettingsPath(), "utf-8");
|
|
79613
80289
|
const parsed = JSON.parse(raw2);
|
|
@@ -79621,9 +80297,9 @@ function isWindows2() {
|
|
|
79621
80297
|
}
|
|
79622
80298
|
function createStatusLineScript(tokenFilePath) {
|
|
79623
80299
|
const homeDir = process.env.HOME || process.env.USERPROFILE || tmpdir2();
|
|
79624
|
-
const claudishDir =
|
|
80300
|
+
const claudishDir = join38(homeDir, ".claudish");
|
|
79625
80301
|
const timestamp = Date.now();
|
|
79626
|
-
const scriptPath =
|
|
80302
|
+
const scriptPath = join38(claudishDir, `status-${timestamp}.js`);
|
|
79627
80303
|
const escapedTokenPath = tokenFilePath.replace(/\\/g, "\\\\");
|
|
79628
80304
|
const script = `
|
|
79629
80305
|
const fs = require('fs');
|
|
@@ -79750,13 +80426,13 @@ process.stdin.on('end', () => {
|
|
|
79750
80426
|
}
|
|
79751
80427
|
});
|
|
79752
80428
|
`;
|
|
79753
|
-
|
|
80429
|
+
writeFileSync21(scriptPath, script, "utf-8");
|
|
79754
80430
|
return scriptPath;
|
|
79755
80431
|
}
|
|
79756
80432
|
function initializeTokenFile(tokenFilePath) {
|
|
79757
80433
|
try {
|
|
79758
|
-
|
|
79759
|
-
|
|
80434
|
+
mkdirSync18(dirname13(tokenFilePath), { recursive: true });
|
|
80435
|
+
writeFileSync21(tokenFilePath, JSON.stringify({
|
|
79760
80436
|
input_tokens: 0,
|
|
79761
80437
|
output_tokens: 0,
|
|
79762
80438
|
total_tokens: 0,
|
|
@@ -79787,11 +80463,11 @@ function cleanupStaleTokenFiles(dir, now = Date.now(), maxAgeMs = STALE_TOKEN_FI
|
|
|
79787
80463
|
if (!name.startsWith("tokens-") || !name.endsWith(".json"))
|
|
79788
80464
|
continue;
|
|
79789
80465
|
scanned++;
|
|
79790
|
-
const full =
|
|
80466
|
+
const full = join38(dir, name);
|
|
79791
80467
|
try {
|
|
79792
80468
|
if (statSync5(full).mtimeMs >= cutoff)
|
|
79793
80469
|
continue;
|
|
79794
|
-
|
|
80470
|
+
unlinkSync10(full);
|
|
79795
80471
|
removed++;
|
|
79796
80472
|
} catch {}
|
|
79797
80473
|
}
|
|
@@ -79804,7 +80480,7 @@ function parseSettingsArg(value) {
|
|
|
79804
80480
|
if (value.trimStart().startsWith("{")) {
|
|
79805
80481
|
return JSON.parse(value);
|
|
79806
80482
|
}
|
|
79807
|
-
return JSON.parse(
|
|
80483
|
+
return JSON.parse(readFileSync30(value, "utf-8"));
|
|
79808
80484
|
}
|
|
79809
80485
|
function parseSettingsArgSafe(value) {
|
|
79810
80486
|
try {
|
|
@@ -79816,13 +80492,13 @@ function parseSettingsArgSafe(value) {
|
|
|
79816
80492
|
}
|
|
79817
80493
|
function userSettingsFileCandidates(cwd) {
|
|
79818
80494
|
return [
|
|
79819
|
-
|
|
79820
|
-
|
|
79821
|
-
|
|
80495
|
+
join38(homedir34(), ".claude", "settings.json"),
|
|
80496
|
+
join38(cwd, ".claude", "settings.json"),
|
|
80497
|
+
join38(cwd, ".claude", "settings.local.json")
|
|
79822
80498
|
];
|
|
79823
80499
|
}
|
|
79824
80500
|
function discoverUserStatusLineCommand(claudeArgs = [], cwd = process.cwd()) {
|
|
79825
|
-
const sources = userSettingsFileCandidates(cwd).filter((file2) =>
|
|
80501
|
+
const sources = userSettingsFileCandidates(cwd).filter((file2) => existsSync30(file2));
|
|
79826
80502
|
const idx = claudeArgs.indexOf("--settings");
|
|
79827
80503
|
const settingsArg = idx === -1 ? undefined : claudeArgs[idx + 1];
|
|
79828
80504
|
if (settingsArg)
|
|
@@ -79859,13 +80535,13 @@ function buildChainedStatusCommand(userCommand, claudishBody, claudishSegment) {
|
|
|
79859
80535
|
}
|
|
79860
80536
|
function createTempSettingsFile(_modelDisplay, port, proxyAuthMode, userStatusLineCommand) {
|
|
79861
80537
|
const homeDir = process.env.HOME || process.env.USERPROFILE || tmpdir2();
|
|
79862
|
-
const claudishDir =
|
|
80538
|
+
const claudishDir = join38(homeDir, ".claudish");
|
|
79863
80539
|
try {
|
|
79864
|
-
|
|
80540
|
+
mkdirSync18(claudishDir, { recursive: true });
|
|
79865
80541
|
} catch {}
|
|
79866
80542
|
const timestamp = Date.now();
|
|
79867
|
-
const tempPath =
|
|
79868
|
-
const tokenFilePath =
|
|
80543
|
+
const tempPath = join38(claudishDir, `settings-${timestamp}.json`);
|
|
80544
|
+
const tokenFilePath = join38(claudishDir, `tokens-${port}.json`);
|
|
79869
80545
|
cleanupStaleTokenFiles(claudishDir);
|
|
79870
80546
|
initializeTokenFile(tokenFilePath);
|
|
79871
80547
|
let statusCommand;
|
|
@@ -79898,7 +80574,7 @@ function createTempSettingsFile(_modelDisplay, port, proxyAuthMode, userStatusLi
|
|
|
79898
80574
|
padding: 0
|
|
79899
80575
|
};
|
|
79900
80576
|
const settings = buildClaudishSettingsOverlay(statusLine, proxyAuthMode);
|
|
79901
|
-
|
|
80577
|
+
writeFileSync21(tempPath, JSON.stringify(settings, null, 2), "utf-8");
|
|
79902
80578
|
return { path: tempPath, statusLine, tokenFilePath };
|
|
79903
80579
|
}
|
|
79904
80580
|
function buildClaudishSettingsOverlay(statusLine, proxyAuthMode) {
|
|
@@ -79923,7 +80599,7 @@ function mergeUserSettingsIfPresent(config3, tempSettingsPath, statusLine, proxy
|
|
|
79923
80599
|
if (proxyAuthMode && !("forceLoginMethod" in userSettings)) {
|
|
79924
80600
|
userSettings.forceLoginMethod = "console";
|
|
79925
80601
|
}
|
|
79926
|
-
|
|
80602
|
+
writeFileSync21(tempSettingsPath, JSON.stringify(userSettings, null, 2), "utf-8");
|
|
79927
80603
|
} catch {
|
|
79928
80604
|
if (!config3.quiet) {
|
|
79929
80605
|
console.warn(`[claudish] Warning: could not merge user settings: ${userSettingsValue}`);
|
|
@@ -80115,8 +80791,8 @@ async function runClaudeWithProxy(config3, proxyUrl, onCleanup) {
|
|
|
80115
80791
|
console.error("Install it from: https://claude.com/claude-code");
|
|
80116
80792
|
console.error(`
|
|
80117
80793
|
Or set CLAUDE_PATH to your custom installation:`);
|
|
80118
|
-
const home =
|
|
80119
|
-
const localPath = isWindows2() ?
|
|
80794
|
+
const home = homedir34();
|
|
80795
|
+
const localPath = isWindows2() ? join38(home, ".claude", "local", "claude.exe") : join38(home, ".claude", "local", "claude");
|
|
80120
80796
|
console.error(` export CLAUDE_PATH=${localPath}`);
|
|
80121
80797
|
process.exit(1);
|
|
80122
80798
|
}
|
|
@@ -80127,11 +80803,11 @@ Or set CLAUDE_PATH to your custom installation:`);
|
|
|
80127
80803
|
const childWantsTty = config3.interactive && !process.stdout.isTTY && Boolean(process.stdin.isTTY);
|
|
80128
80804
|
if (childWantsTty) {
|
|
80129
80805
|
try {
|
|
80130
|
-
const fd =
|
|
80806
|
+
const fd = openSync5("/dev/fd/0", "r+");
|
|
80131
80807
|
if (isatty(fd)) {
|
|
80132
80808
|
ttyFd = fd;
|
|
80133
80809
|
} else {
|
|
80134
|
-
|
|
80810
|
+
closeSync5(fd);
|
|
80135
80811
|
}
|
|
80136
80812
|
} catch {
|
|
80137
80813
|
ttyFd = undefined;
|
|
@@ -80154,7 +80830,7 @@ Or set CLAUDE_PATH to your custom installation:`);
|
|
|
80154
80830
|
const fdToClose = ttyFd;
|
|
80155
80831
|
proc.on("spawn", () => {
|
|
80156
80832
|
try {
|
|
80157
|
-
|
|
80833
|
+
closeSync5(fdToClose);
|
|
80158
80834
|
} catch {}
|
|
80159
80835
|
});
|
|
80160
80836
|
}
|
|
@@ -80167,7 +80843,7 @@ Or set CLAUDE_PATH to your custom installation:`);
|
|
|
80167
80843
|
});
|
|
80168
80844
|
releaseTerminalIsolation();
|
|
80169
80845
|
try {
|
|
80170
|
-
|
|
80846
|
+
unlinkSync10(tempSettingsPath);
|
|
80171
80847
|
} catch {}
|
|
80172
80848
|
return exitCode;
|
|
80173
80849
|
}
|
|
@@ -80187,7 +80863,7 @@ function setupSignalHandlers(proc, tempSettingsPath, quiet, onCleanup) {
|
|
|
80187
80863
|
} catch {}
|
|
80188
80864
|
}
|
|
80189
80865
|
try {
|
|
80190
|
-
|
|
80866
|
+
unlinkSync10(tempSettingsPath);
|
|
80191
80867
|
} catch {}
|
|
80192
80868
|
process.exit(0);
|
|
80193
80869
|
});
|
|
@@ -80196,23 +80872,23 @@ function setupSignalHandlers(proc, tempSettingsPath, quiet, onCleanup) {
|
|
|
80196
80872
|
async function findClaudeBinary() {
|
|
80197
80873
|
const isWindows3 = process.platform === "win32";
|
|
80198
80874
|
if (process.env.CLAUDE_PATH) {
|
|
80199
|
-
if (
|
|
80875
|
+
if (existsSync30(process.env.CLAUDE_PATH)) {
|
|
80200
80876
|
return process.env.CLAUDE_PATH;
|
|
80201
80877
|
}
|
|
80202
80878
|
}
|
|
80203
|
-
const home =
|
|
80204
|
-
const localPath = isWindows3 ?
|
|
80205
|
-
if (
|
|
80879
|
+
const home = homedir34();
|
|
80880
|
+
const localPath = isWindows3 ? join38(home, ".claude", "local", "claude.exe") : join38(home, ".claude", "local", "claude");
|
|
80881
|
+
if (existsSync30(localPath)) {
|
|
80206
80882
|
return localPath;
|
|
80207
80883
|
}
|
|
80208
80884
|
if (isWindows3) {
|
|
80209
80885
|
const windowsPaths = [
|
|
80210
|
-
|
|
80211
|
-
|
|
80212
|
-
|
|
80886
|
+
join38(home, "AppData", "Roaming", "npm", "claude.cmd"),
|
|
80887
|
+
join38(home, ".npm-global", "claude.cmd"),
|
|
80888
|
+
join38(home, "node_modules", ".bin", "claude.cmd")
|
|
80213
80889
|
];
|
|
80214
80890
|
for (const path2 of windowsPaths) {
|
|
80215
|
-
if (
|
|
80891
|
+
if (existsSync30(path2)) {
|
|
80216
80892
|
return path2;
|
|
80217
80893
|
}
|
|
80218
80894
|
}
|
|
@@ -80220,14 +80896,14 @@ async function findClaudeBinary() {
|
|
|
80220
80896
|
const commonPaths = [
|
|
80221
80897
|
"/usr/local/bin/claude",
|
|
80222
80898
|
"/opt/homebrew/bin/claude",
|
|
80223
|
-
|
|
80224
|
-
|
|
80225
|
-
|
|
80899
|
+
join38(home, ".npm-global/bin/claude"),
|
|
80900
|
+
join38(home, ".local/bin/claude"),
|
|
80901
|
+
join38(home, "node_modules/.bin/claude"),
|
|
80226
80902
|
"/data/data/com.termux/files/usr/bin/claude",
|
|
80227
|
-
|
|
80903
|
+
join38(home, "../usr/bin/claude")
|
|
80228
80904
|
];
|
|
80229
80905
|
for (const path2 of commonPaths) {
|
|
80230
|
-
if (
|
|
80906
|
+
if (existsSync30(path2)) {
|
|
80231
80907
|
return path2;
|
|
80232
80908
|
}
|
|
80233
80909
|
}
|
|
@@ -80286,18 +80962,18 @@ __export(exports_diag_output, {
|
|
|
80286
80962
|
NullDiagOutput: () => NullDiagOutput,
|
|
80287
80963
|
LogFileDiagOutput: () => LogFileDiagOutput
|
|
80288
80964
|
});
|
|
80289
|
-
import { createWriteStream as createWriteStream3, mkdirSync as
|
|
80290
|
-
import { homedir as
|
|
80291
|
-
import { join as
|
|
80965
|
+
import { createWriteStream as createWriteStream3, mkdirSync as mkdirSync19, unlinkSync as unlinkSync11, writeFileSync as writeFileSync22 } from "fs";
|
|
80966
|
+
import { homedir as homedir35 } from "os";
|
|
80967
|
+
import { join as join39 } from "path";
|
|
80292
80968
|
function getClaudishDir() {
|
|
80293
|
-
const dir =
|
|
80969
|
+
const dir = join39(homedir35(), ".claudish");
|
|
80294
80970
|
try {
|
|
80295
|
-
|
|
80971
|
+
mkdirSync19(dir, { recursive: true });
|
|
80296
80972
|
} catch {}
|
|
80297
80973
|
return dir;
|
|
80298
80974
|
}
|
|
80299
80975
|
function getDiagLogPath() {
|
|
80300
|
-
return
|
|
80976
|
+
return join39(getClaudishDir(), `diag-${process.pid}.log`);
|
|
80301
80977
|
}
|
|
80302
80978
|
|
|
80303
80979
|
class LogFileDiagOutput {
|
|
@@ -80306,7 +80982,7 @@ class LogFileDiagOutput {
|
|
|
80306
80982
|
constructor() {
|
|
80307
80983
|
this.logPath = getDiagLogPath();
|
|
80308
80984
|
try {
|
|
80309
|
-
|
|
80985
|
+
writeFileSync22(this.logPath, `--- claudish diag session ${new Date().toISOString()} ---
|
|
80310
80986
|
`);
|
|
80311
80987
|
} catch {}
|
|
80312
80988
|
this.stream = createWriteStream3(this.logPath, { flags: "a" });
|
|
@@ -80325,7 +81001,7 @@ class LogFileDiagOutput {
|
|
|
80325
81001
|
this.stream.end();
|
|
80326
81002
|
} catch {}
|
|
80327
81003
|
try {
|
|
80328
|
-
|
|
81004
|
+
unlinkSync11(this.logPath);
|
|
80329
81005
|
} catch {}
|
|
80330
81006
|
}
|
|
80331
81007
|
getLogPath() {
|
|
@@ -80893,9 +81569,9 @@ __export(exports_session_discovery, {
|
|
|
80893
81569
|
ACTIVE_WINDOW_MS: () => ACTIVE_WINDOW_MS
|
|
80894
81570
|
});
|
|
80895
81571
|
import { execFile, execFileSync as execFileSync2 } from "child_process";
|
|
80896
|
-
import { closeSync as
|
|
80897
|
-
import { homedir as
|
|
80898
|
-
import { basename, join as
|
|
81572
|
+
import { closeSync as closeSync6, openSync as openSync6, readSync, readdirSync as readdirSync7, statSync as statSync6 } from "fs";
|
|
81573
|
+
import { homedir as homedir36 } from "os";
|
|
81574
|
+
import { basename, join as join40 } from "path";
|
|
80899
81575
|
function slugForPath(absPath) {
|
|
80900
81576
|
return absPath.replace(/[/.]/g, "-");
|
|
80901
81577
|
}
|
|
@@ -80944,7 +81620,7 @@ function projectDirs() {
|
|
|
80944
81620
|
}
|
|
80945
81621
|
}
|
|
80946
81622
|
function sessionsIn(dirName) {
|
|
80947
|
-
const dir =
|
|
81623
|
+
const dir = join40(PROJECTS_DIR, dirName);
|
|
80948
81624
|
let names;
|
|
80949
81625
|
try {
|
|
80950
81626
|
names = readdirSync7(dir).filter((n) => n.endsWith(".jsonl"));
|
|
@@ -80953,7 +81629,7 @@ function sessionsIn(dirName) {
|
|
|
80953
81629
|
}
|
|
80954
81630
|
const rows = [];
|
|
80955
81631
|
for (const n of names) {
|
|
80956
|
-
const file2 =
|
|
81632
|
+
const file2 = join40(dir, n);
|
|
80957
81633
|
try {
|
|
80958
81634
|
const st = statSync6(file2);
|
|
80959
81635
|
if (st.size === 0)
|
|
@@ -81133,7 +81809,7 @@ function readChunk(file2, pos, len) {
|
|
|
81133
81809
|
return "";
|
|
81134
81810
|
let fd = null;
|
|
81135
81811
|
try {
|
|
81136
|
-
fd =
|
|
81812
|
+
fd = openSync6(file2, "r");
|
|
81137
81813
|
const buf = Buffer.allocUnsafe(len);
|
|
81138
81814
|
const n = readSync(fd, buf, 0, len, pos);
|
|
81139
81815
|
return buf.subarray(0, n).toString("utf-8");
|
|
@@ -81142,7 +81818,7 @@ function readChunk(file2, pos, len) {
|
|
|
81142
81818
|
} finally {
|
|
81143
81819
|
if (fd !== null) {
|
|
81144
81820
|
try {
|
|
81145
|
-
|
|
81821
|
+
closeSync6(fd);
|
|
81146
81822
|
} catch {}
|
|
81147
81823
|
}
|
|
81148
81824
|
}
|
|
@@ -81312,7 +81988,7 @@ function findLatestSessionId(cwd = process.cwd(), sinceMs = 0) {
|
|
|
81312
81988
|
}
|
|
81313
81989
|
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
81990
|
var init_session_discovery = __esm(() => {
|
|
81315
|
-
PROJECTS_DIR =
|
|
81991
|
+
PROJECTS_DIR = join40(homedir36(), ".claude", "projects");
|
|
81316
81992
|
HEAD_BYTES = 64 * 1024;
|
|
81317
81993
|
TAIL_BYTES = 128 * 1024;
|
|
81318
81994
|
HARNESS_ENVELOPES = [
|
|
@@ -81325,7 +82001,7 @@ var init_session_discovery = __esm(() => {
|
|
|
81325
82001
|
});
|
|
81326
82002
|
|
|
81327
82003
|
// src/session/conversation.ts
|
|
81328
|
-
import { closeSync as
|
|
82004
|
+
import { closeSync as closeSync7, openSync as openSync7, readSync as readSync2, statSync as statSync7 } from "fs";
|
|
81329
82005
|
import { StringDecoder } from "string_decoder";
|
|
81330
82006
|
function looksLikeTurn(line) {
|
|
81331
82007
|
const assistant = line.includes('"type":"assistant"');
|
|
@@ -81381,7 +82057,7 @@ function readConversation(file2, opts = {}) {
|
|
|
81381
82057
|
let fd = null;
|
|
81382
82058
|
try {
|
|
81383
82059
|
const size = statSync7(file2).size;
|
|
81384
|
-
fd =
|
|
82060
|
+
fd = openSync7(file2, "r");
|
|
81385
82061
|
const buf = Buffer.allocUnsafe(chunkBytes);
|
|
81386
82062
|
const decoder = new StringDecoder("utf-8");
|
|
81387
82063
|
let pending = "";
|
|
@@ -81437,7 +82113,7 @@ function readConversation(file2, opts = {}) {
|
|
|
81437
82113
|
} catch {} finally {
|
|
81438
82114
|
if (fd !== null) {
|
|
81439
82115
|
try {
|
|
81440
|
-
|
|
82116
|
+
closeSync7(fd);
|
|
81441
82117
|
} catch {}
|
|
81442
82118
|
}
|
|
81443
82119
|
}
|
|
@@ -83004,16 +83680,16 @@ __export(exports_session_stats, {
|
|
|
83004
83680
|
readSessionStats: () => readSessionStats,
|
|
83005
83681
|
computeSavings: () => computeSavings
|
|
83006
83682
|
});
|
|
83007
|
-
import { readFileSync as
|
|
83008
|
-
import { homedir as
|
|
83009
|
-
import { join as
|
|
83683
|
+
import { readFileSync as readFileSync31 } from "fs";
|
|
83684
|
+
import { homedir as homedir37 } from "os";
|
|
83685
|
+
import { join as join41 } from "path";
|
|
83010
83686
|
function tokenFilePath(port) {
|
|
83011
|
-
return process.env.CLAUDISH_TOKEN_FILE ||
|
|
83687
|
+
return process.env.CLAUDISH_TOKEN_FILE || join41(homedir37(), ".claudish", `tokens-${port}.json`);
|
|
83012
83688
|
}
|
|
83013
83689
|
function readSessionStats(port, opts) {
|
|
83014
83690
|
let raw2;
|
|
83015
83691
|
try {
|
|
83016
|
-
raw2 = JSON.parse(
|
|
83692
|
+
raw2 = JSON.parse(readFileSync31(tokenFilePath(port), "utf-8"));
|
|
83017
83693
|
} catch {
|
|
83018
83694
|
return null;
|
|
83019
83695
|
}
|
|
@@ -83353,8 +84029,8 @@ var init_session_summary = __esm(() => {
|
|
|
83353
84029
|
init_op_source();
|
|
83354
84030
|
init_startup_trace();
|
|
83355
84031
|
var import_dotenv3 = __toESM(require_main(), 1);
|
|
83356
|
-
import { existsSync as
|
|
83357
|
-
import { join as
|
|
84032
|
+
import { existsSync as existsSync31, readFileSync as readFileSync32 } from "fs";
|
|
84033
|
+
import { join as join42, resolve as resolve5 } from "path";
|
|
83358
84034
|
import_dotenv3.config({ quiet: true });
|
|
83359
84035
|
function classifyStartupKind() {
|
|
83360
84036
|
const argv = process.argv.slice(2);
|
|
@@ -83453,7 +84129,7 @@ async function applyConfigOverride() {
|
|
|
83453
84129
|
const { planConfigOverride: planConfigOverride2, setConfigFileOverride: setConfigFileOverride2 } = await Promise.resolve().then(() => exports_config_override);
|
|
83454
84130
|
const plan = planConfigOverride2(process.argv.slice(2), process.env, {
|
|
83455
84131
|
resolve: resolve5,
|
|
83456
|
-
exists:
|
|
84132
|
+
exists: existsSync31
|
|
83457
84133
|
});
|
|
83458
84134
|
if (plan.kind === "none")
|
|
83459
84135
|
return;
|
|
@@ -83608,14 +84284,14 @@ async function runCli() {
|
|
|
83608
84284
|
if (cliConfig.team && cliConfig.team.length > 0) {
|
|
83609
84285
|
let prompt = cliConfig.claudeArgs.join(" ");
|
|
83610
84286
|
if (cliConfig.inputFile) {
|
|
83611
|
-
prompt =
|
|
84287
|
+
prompt = readFileSync32(cliConfig.inputFile, "utf-8");
|
|
83612
84288
|
}
|
|
83613
84289
|
if (!prompt.trim()) {
|
|
83614
84290
|
console.error("Error: --team requires a prompt (positional args or -f <file>)");
|
|
83615
84291
|
process.exit(1);
|
|
83616
84292
|
}
|
|
83617
84293
|
const mode = cliConfig.teamMode ?? "default";
|
|
83618
|
-
const sessionPath =
|
|
84294
|
+
const sessionPath = join42(process.cwd(), `.claudish-team-${Date.now()}`);
|
|
83619
84295
|
if (mode === "json") {
|
|
83620
84296
|
const { setupSession: setupSession2, runModels: runModels2 } = await Promise.resolve().then(() => (init_team_orchestrator(), exports_team_orchestrator));
|
|
83621
84297
|
setupSession2(sessionPath, cliConfig.team, prompt);
|
|
@@ -83625,9 +84301,9 @@ async function runCli() {
|
|
|
83625
84301
|
});
|
|
83626
84302
|
const result = { ...status2, responses: {} };
|
|
83627
84303
|
for (const anonId of Object.keys(status2.models)) {
|
|
83628
|
-
const responsePath =
|
|
84304
|
+
const responsePath = join42(sessionPath, `response-${anonId}.md`);
|
|
83629
84305
|
try {
|
|
83630
|
-
const raw2 =
|
|
84306
|
+
const raw2 = readFileSync32(responsePath, "utf-8").trim();
|
|
83631
84307
|
try {
|
|
83632
84308
|
result.responses[anonId] = JSON.parse(raw2);
|
|
83633
84309
|
} catch {
|