claudish 9.6.0 → 9.7.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 +816 -467
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -715,7 +715,7 @@ var init_onepassword_config = __esm(() => {
|
|
|
715
715
|
});
|
|
716
716
|
|
|
717
717
|
// src/version.ts
|
|
718
|
-
var VERSION = "9.
|
|
718
|
+
var VERSION = "9.7.0";
|
|
719
719
|
|
|
720
720
|
// src/logger.ts
|
|
721
721
|
import { appendFile, existsSync as existsSync2, mkdirSync, readdirSync, unlinkSync, writeFileSync as writeFileSync2 } from "fs";
|
|
@@ -18165,10 +18165,122 @@ var init_stdio2 = __esm(() => {
|
|
|
18165
18165
|
init_stdio();
|
|
18166
18166
|
});
|
|
18167
18167
|
|
|
18168
|
-
// src/providers/
|
|
18169
|
-
import { existsSync as existsSync5, mkdirSync as mkdirSync5, readFileSync as readFileSync5, writeFileSync as writeFileSync5 } from "fs";
|
|
18168
|
+
// src/providers/catalog-compatibility.ts
|
|
18169
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync5, readFileSync as readFileSync5, rmSync as rmSync2, writeFileSync as writeFileSync5 } from "fs";
|
|
18170
18170
|
import { homedir as homedir7 } from "os";
|
|
18171
18171
|
import { dirname as dirname4, join as join7 } from "path";
|
|
18172
|
+
function parseContractEnvelope(body) {
|
|
18173
|
+
if (!body || typeof body !== "object")
|
|
18174
|
+
return { contractVersion: null };
|
|
18175
|
+
const data = body;
|
|
18176
|
+
const contractVersion = typeof data.contractVersion === "number" ? data.contractVersion : null;
|
|
18177
|
+
const err = data.error;
|
|
18178
|
+
const minimum = err && typeof err === "object" ? err.minimumContractVersion : undefined;
|
|
18179
|
+
return {
|
|
18180
|
+
contractVersion,
|
|
18181
|
+
...typeof minimum === "number" ? { minimumContractVersion: minimum } : {}
|
|
18182
|
+
};
|
|
18183
|
+
}
|
|
18184
|
+
function isIncompatibleContractVersion(version) {
|
|
18185
|
+
return typeof version === "number" && version > SUPPORTED_CONTRACT_VERSION;
|
|
18186
|
+
}
|
|
18187
|
+
function markCatalogIncompatible(info, path = CATALOG_INCOMPATIBLE_PATH) {
|
|
18188
|
+
const record = {
|
|
18189
|
+
detectedAt: new Date().toISOString(),
|
|
18190
|
+
serverContractVersion: info.serverContractVersion,
|
|
18191
|
+
clientContractVersion: SUPPORTED_CONTRACT_VERSION,
|
|
18192
|
+
...info.minimumContractVersion !== undefined ? { minimumContractVersion: info.minimumContractVersion } : {}
|
|
18193
|
+
};
|
|
18194
|
+
_memFlag = record;
|
|
18195
|
+
_fileMemo = { path, value: record };
|
|
18196
|
+
try {
|
|
18197
|
+
mkdirSync5(dirname4(path), { recursive: true });
|
|
18198
|
+
writeFileSync5(path, JSON.stringify(record), "utf-8");
|
|
18199
|
+
} catch {}
|
|
18200
|
+
}
|
|
18201
|
+
function readCatalogIncompatibility(path = CATALOG_INCOMPATIBLE_PATH) {
|
|
18202
|
+
if (_memFlag)
|
|
18203
|
+
return _memFlag;
|
|
18204
|
+
if (_fileMemo && _fileMemo.path === path)
|
|
18205
|
+
return _fileMemo.value;
|
|
18206
|
+
let value = null;
|
|
18207
|
+
try {
|
|
18208
|
+
if (existsSync5(path))
|
|
18209
|
+
value = parseSentinelFile(readFileSync5(path, "utf-8"));
|
|
18210
|
+
} catch {}
|
|
18211
|
+
if (value !== null && isSentinelStale(value)) {
|
|
18212
|
+
clearCatalogIncompatibility(path);
|
|
18213
|
+
return null;
|
|
18214
|
+
}
|
|
18215
|
+
_fileMemo = { path, value };
|
|
18216
|
+
return value;
|
|
18217
|
+
}
|
|
18218
|
+
function isSentinelStale(record) {
|
|
18219
|
+
if (typeof record.minimumContractVersion === "number" && record.minimumContractVersion > SUPPORTED_CONTRACT_VERSION) {
|
|
18220
|
+
return false;
|
|
18221
|
+
}
|
|
18222
|
+
if (record.serverContractVersion !== null) {
|
|
18223
|
+
return record.serverContractVersion <= SUPPORTED_CONTRACT_VERSION;
|
|
18224
|
+
}
|
|
18225
|
+
if (typeof record.clientContractVersion === "number") {
|
|
18226
|
+
return record.clientContractVersion < SUPPORTED_CONTRACT_VERSION;
|
|
18227
|
+
}
|
|
18228
|
+
return false;
|
|
18229
|
+
}
|
|
18230
|
+
function parseSentinelFile(raw) {
|
|
18231
|
+
const unspecific = {
|
|
18232
|
+
detectedAt: new Date(0).toISOString(),
|
|
18233
|
+
serverContractVersion: null
|
|
18234
|
+
};
|
|
18235
|
+
let parsed;
|
|
18236
|
+
try {
|
|
18237
|
+
parsed = JSON.parse(raw);
|
|
18238
|
+
} catch {
|
|
18239
|
+
return unspecific;
|
|
18240
|
+
}
|
|
18241
|
+
if (!parsed || typeof parsed !== "object")
|
|
18242
|
+
return unspecific;
|
|
18243
|
+
const data = parsed;
|
|
18244
|
+
return {
|
|
18245
|
+
detectedAt: typeof data.detectedAt === "string" ? data.detectedAt : unspecific.detectedAt,
|
|
18246
|
+
serverContractVersion: typeof data.serverContractVersion === "number" ? data.serverContractVersion : null,
|
|
18247
|
+
...typeof data.minimumContractVersion === "number" ? { minimumContractVersion: data.minimumContractVersion } : {},
|
|
18248
|
+
...typeof data.clientContractVersion === "number" ? { clientContractVersion: data.clientContractVersion } : {}
|
|
18249
|
+
};
|
|
18250
|
+
}
|
|
18251
|
+
function clearCatalogIncompatibility(path = CATALOG_INCOMPATIBLE_PATH) {
|
|
18252
|
+
_memFlag = null;
|
|
18253
|
+
_fileMemo = { path, value: null };
|
|
18254
|
+
try {
|
|
18255
|
+
rmSync2(path, { force: true });
|
|
18256
|
+
} catch {}
|
|
18257
|
+
}
|
|
18258
|
+
function catalogIncompatibilityMessage(i) {
|
|
18259
|
+
const serverSays = typeof i.serverContractVersion === "number" ? `catalog contract version ${i.serverContractVersion}` : typeof i.minimumContractVersion === "number" ? `catalog contract version ${i.minimumContractVersion} or newer` : "a newer catalog contract";
|
|
18260
|
+
return [
|
|
18261
|
+
`This claudish build cannot read the model catalog. The catalog server publishes ${serverSays}; this build reads version ${SUPPORTED_CONTRACT_VERSION}.`,
|
|
18262
|
+
"",
|
|
18263
|
+
"Routing cannot tell which models your subscriptions cover, so continuing would send this request to a provider that bills per token without saying so.",
|
|
18264
|
+
"",
|
|
18265
|
+
"Run `claudish update` to get a build that reads the current catalog."
|
|
18266
|
+
].join(`
|
|
18267
|
+
`);
|
|
18268
|
+
}
|
|
18269
|
+
var SUPPORTED_CONTRACT_VERSION = 2, CATALOG_INCOMPATIBLE_PATH, _memFlag = null, _fileMemo = null, CatalogIncompatibleError;
|
|
18270
|
+
var init_catalog_compatibility = __esm(() => {
|
|
18271
|
+
CATALOG_INCOMPATIBLE_PATH = join7(homedir7(), ".claudish", "catalog-incompatible.json");
|
|
18272
|
+
CatalogIncompatibleError = class CatalogIncompatibleError extends Error {
|
|
18273
|
+
constructor(message) {
|
|
18274
|
+
super(message);
|
|
18275
|
+
this.name = "CatalogIncompatibleError";
|
|
18276
|
+
}
|
|
18277
|
+
};
|
|
18278
|
+
});
|
|
18279
|
+
|
|
18280
|
+
// src/providers/all-models-cache.ts
|
|
18281
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync6, readFileSync as readFileSync6, writeFileSync as writeFileSync6 } from "fs";
|
|
18282
|
+
import { homedir as homedir8 } from "os";
|
|
18283
|
+
import { dirname as dirname5, join as join8 } from "path";
|
|
18172
18284
|
function reasoningStatusOf(entry) {
|
|
18173
18285
|
if (entry.reasoningStatus === "known" || entry.reasoningStatus === "unknown") {
|
|
18174
18286
|
return entry.reasoningStatus;
|
|
@@ -18176,11 +18288,16 @@ function reasoningStatusOf(entry) {
|
|
|
18176
18288
|
return entry.reasoning !== undefined ? "known" : "unknown";
|
|
18177
18289
|
}
|
|
18178
18290
|
function readAllModelsCache(path = ALL_MODELS_CACHE_PATH) {
|
|
18179
|
-
if (
|
|
18291
|
+
if (readCatalogIncompatibility())
|
|
18292
|
+
return null;
|
|
18293
|
+
return readCacheFile(path);
|
|
18294
|
+
}
|
|
18295
|
+
function readCacheFile(path) {
|
|
18296
|
+
if (!existsSync6(path))
|
|
18180
18297
|
return null;
|
|
18181
18298
|
let raw;
|
|
18182
18299
|
try {
|
|
18183
|
-
raw = JSON.parse(
|
|
18300
|
+
raw = JSON.parse(readFileSync6(path, "utf-8"));
|
|
18184
18301
|
} catch {
|
|
18185
18302
|
return null;
|
|
18186
18303
|
}
|
|
@@ -18202,7 +18319,7 @@ function readAllModelsCache(path = ALL_MODELS_CACHE_PATH) {
|
|
|
18202
18319
|
};
|
|
18203
18320
|
}
|
|
18204
18321
|
function writeAllModelsCache(data, path = ALL_MODELS_CACHE_PATH) {
|
|
18205
|
-
const existing =
|
|
18322
|
+
const existing = readCacheFile(path);
|
|
18206
18323
|
const merged = {
|
|
18207
18324
|
version: 2,
|
|
18208
18325
|
lastUpdated: data.lastUpdated ?? new Date().toISOString(),
|
|
@@ -18211,12 +18328,13 @@ function writeAllModelsCache(data, path = ALL_MODELS_CACHE_PATH) {
|
|
|
18211
18328
|
...data.plans !== undefined || existing?.plans !== undefined ? { plans: data.plans ?? existing?.plans ?? [] } : {},
|
|
18212
18329
|
...data.catalogRevision !== undefined ? { catalogRevision: data.catalogRevision } : {}
|
|
18213
18330
|
};
|
|
18214
|
-
|
|
18215
|
-
|
|
18331
|
+
mkdirSync6(dirname5(path), { recursive: true });
|
|
18332
|
+
writeFileSync6(path, JSON.stringify(merged), "utf-8");
|
|
18216
18333
|
}
|
|
18217
18334
|
var ALL_MODELS_CACHE_PATH;
|
|
18218
18335
|
var init_all_models_cache = __esm(() => {
|
|
18219
|
-
|
|
18336
|
+
init_catalog_compatibility();
|
|
18337
|
+
ALL_MODELS_CACHE_PATH = join8(homedir8(), ".claudish", "all-models.json");
|
|
18220
18338
|
});
|
|
18221
18339
|
|
|
18222
18340
|
// src/providers/model-ordering.ts
|
|
@@ -18370,19 +18488,25 @@ function resolveSubscriptionRouting(modelId, provider, cachePath) {
|
|
|
18370
18488
|
if (providerPlans.length === 0)
|
|
18371
18489
|
return { kind: "unknown" };
|
|
18372
18490
|
const providerPlanIds = new Set(providerPlans.map((plan) => plan.id));
|
|
18373
|
-
const
|
|
18374
|
-
|
|
18491
|
+
const memberships = entry.subscriptionPlans ?? [];
|
|
18492
|
+
const includingPlans = providerPlans.filter((plan) => memberships.includes(plan.id));
|
|
18493
|
+
if (includingPlans.length > 0) {
|
|
18494
|
+
if (includingPlans.length < providerPlans.length)
|
|
18495
|
+
return { kind: "unknown" };
|
|
18375
18496
|
const agg = entry.aggregators?.find((a) => a.provider === provider);
|
|
18376
18497
|
return agg?.externalId ? { kind: "serves", externalId: agg.externalId } : { kind: "unknown" };
|
|
18377
18498
|
}
|
|
18378
|
-
const
|
|
18379
|
-
if (!
|
|
18499
|
+
const hasAnyMembershipRow = cache.entries.some((candidate) => candidate.subscriptionPlans?.some((planId) => providerPlanIds.has(planId)));
|
|
18500
|
+
if (!hasAnyMembershipRow)
|
|
18380
18501
|
return { kind: "unknown" };
|
|
18381
18502
|
const vendorsInView = new Set(providerPlans.map((plan) => plan.provider).filter((v) => v !== undefined));
|
|
18382
18503
|
const hasUnroutableSiblingPlan = (cache.plans ?? []).some((plan) => plan.provider !== undefined && vendorsInView.has(plan.provider) && plan.routing?.providerUid === undefined);
|
|
18383
18504
|
if (hasUnroutableSiblingPlan)
|
|
18384
18505
|
return { kind: "unknown" };
|
|
18385
|
-
|
|
18506
|
+
const hasCompleteMembershipView = providerPlans.every(isCatalogDiscoveredPlan);
|
|
18507
|
+
if (!hasCompleteMembershipView)
|
|
18508
|
+
return { kind: "unknown" };
|
|
18509
|
+
return { kind: "not-served" };
|
|
18386
18510
|
}
|
|
18387
18511
|
function isCatalogDiscoveredPlan(plan) {
|
|
18388
18512
|
return plan.modelDiscovery === "catalog";
|
|
@@ -18570,26 +18694,26 @@ var init_agent_availability = __esm(() => {
|
|
|
18570
18694
|
});
|
|
18571
18695
|
|
|
18572
18696
|
// src/profile-config.ts
|
|
18573
|
-
import { existsSync as
|
|
18574
|
-
import { homedir as
|
|
18575
|
-
import { dirname as
|
|
18697
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync7, readFileSync as readFileSync7, writeFileSync as writeFileSync7 } from "fs";
|
|
18698
|
+
import { homedir as homedir9 } from "os";
|
|
18699
|
+
import { dirname as dirname6, join as join9, parse as parse6 } from "path";
|
|
18576
18700
|
function activeConfigFile() {
|
|
18577
18701
|
return activeGlobalConfigFile(CONFIG_FILE);
|
|
18578
18702
|
}
|
|
18579
18703
|
function ensureConfigDir() {
|
|
18580
|
-
if (!
|
|
18581
|
-
|
|
18704
|
+
if (!existsSync7(CONFIG_DIR)) {
|
|
18705
|
+
mkdirSync7(CONFIG_DIR, { recursive: true });
|
|
18582
18706
|
}
|
|
18583
18707
|
}
|
|
18584
18708
|
function loadConfig() {
|
|
18585
18709
|
const activeFile = activeConfigFile();
|
|
18586
18710
|
if (!getConfigFileOverride())
|
|
18587
18711
|
ensureConfigDir();
|
|
18588
|
-
if (!
|
|
18712
|
+
if (!existsSync7(activeFile)) {
|
|
18589
18713
|
return { ...DEFAULT_CONFIG };
|
|
18590
18714
|
}
|
|
18591
18715
|
try {
|
|
18592
|
-
const content =
|
|
18716
|
+
const content = readFileSync7(activeFile, "utf-8");
|
|
18593
18717
|
const config = JSON.parse(content);
|
|
18594
18718
|
const merged = {
|
|
18595
18719
|
version: config.version || DEFAULT_CONFIG.version,
|
|
@@ -18659,39 +18783,39 @@ function loadConfig() {
|
|
|
18659
18783
|
function saveConfig(config) {
|
|
18660
18784
|
if (!getConfigFileOverride())
|
|
18661
18785
|
ensureConfigDir();
|
|
18662
|
-
|
|
18786
|
+
writeFileSync7(activeConfigFile(), JSON.stringify(config, null, 2), "utf-8");
|
|
18663
18787
|
}
|
|
18664
18788
|
function configExists() {
|
|
18665
|
-
return
|
|
18789
|
+
return existsSync7(CONFIG_FILE);
|
|
18666
18790
|
}
|
|
18667
18791
|
function getConfigPath() {
|
|
18668
18792
|
return CONFIG_FILE;
|
|
18669
18793
|
}
|
|
18670
18794
|
function getLocalConfigPath() {
|
|
18671
|
-
const home =
|
|
18795
|
+
const home = homedir9();
|
|
18672
18796
|
let dir = process.cwd();
|
|
18673
18797
|
const root = parse6(dir).root;
|
|
18674
18798
|
while (dir !== root && dir !== home) {
|
|
18675
|
-
const candidate =
|
|
18676
|
-
if (
|
|
18799
|
+
const candidate = join9(dir, LOCAL_CONFIG_FILENAME);
|
|
18800
|
+
if (existsSync7(candidate))
|
|
18677
18801
|
return candidate;
|
|
18678
|
-
if (
|
|
18802
|
+
if (existsSync7(join9(dir, ".git"))) {
|
|
18679
18803
|
return candidate;
|
|
18680
18804
|
}
|
|
18681
|
-
dir =
|
|
18805
|
+
dir = dirname6(dir);
|
|
18682
18806
|
}
|
|
18683
|
-
return
|
|
18807
|
+
return join9(process.cwd(), LOCAL_CONFIG_FILENAME);
|
|
18684
18808
|
}
|
|
18685
18809
|
function localConfigExists() {
|
|
18686
|
-
return
|
|
18810
|
+
return existsSync7(getLocalConfigPath());
|
|
18687
18811
|
}
|
|
18688
18812
|
function readProOnUltracode(paths = defaultScopedConfigPaths) {
|
|
18689
18813
|
for (const pathFn of [paths.project, paths.global]) {
|
|
18690
18814
|
try {
|
|
18691
18815
|
const path = pathFn();
|
|
18692
|
-
if (!
|
|
18816
|
+
if (!existsSync7(path))
|
|
18693
18817
|
continue;
|
|
18694
|
-
const parsed = JSON.parse(
|
|
18818
|
+
const parsed = JSON.parse(readFileSync7(path, "utf-8"));
|
|
18695
18819
|
if (typeof parsed?.proOnUltracode === "boolean")
|
|
18696
18820
|
return parsed.proOnUltracode;
|
|
18697
18821
|
} catch {}
|
|
@@ -18700,17 +18824,17 @@ function readProOnUltracode(paths = defaultScopedConfigPaths) {
|
|
|
18700
18824
|
}
|
|
18701
18825
|
function isProjectDirectory() {
|
|
18702
18826
|
const cwd = process.cwd();
|
|
18703
|
-
return [".git", "package.json", "Cargo.toml", "go.mod", "pyproject.toml", ".claudish.json"].some((f) =>
|
|
18827
|
+
return [".git", "package.json", "Cargo.toml", "go.mod", "pyproject.toml", ".claudish.json"].some((f) => existsSync7(join9(cwd, f)));
|
|
18704
18828
|
}
|
|
18705
18829
|
function loadLocalConfig() {
|
|
18706
18830
|
if (getConfigFileOverride())
|
|
18707
18831
|
return null;
|
|
18708
18832
|
const localPath = getLocalConfigPath();
|
|
18709
|
-
if (!
|
|
18833
|
+
if (!existsSync7(localPath)) {
|
|
18710
18834
|
return null;
|
|
18711
18835
|
}
|
|
18712
18836
|
try {
|
|
18713
|
-
const content =
|
|
18837
|
+
const content = readFileSync7(localPath, "utf-8");
|
|
18714
18838
|
const config = JSON.parse(content);
|
|
18715
18839
|
return {
|
|
18716
18840
|
...config,
|
|
@@ -18728,7 +18852,7 @@ function saveLocalConfig(config) {
|
|
|
18728
18852
|
if (toWrite.routing !== undefined && Object.keys(toWrite.routing).length === 0) {
|
|
18729
18853
|
delete toWrite.routing;
|
|
18730
18854
|
}
|
|
18731
|
-
|
|
18855
|
+
writeFileSync7(getLocalConfigPath(), JSON.stringify(toWrite, null, 2), "utf-8");
|
|
18732
18856
|
}
|
|
18733
18857
|
function loadConfigForScope(scope) {
|
|
18734
18858
|
if (scope === "local") {
|
|
@@ -18976,8 +19100,8 @@ function disableLocalProvider(providerName) {
|
|
|
18976
19100
|
}
|
|
18977
19101
|
var CONFIG_DIR, CONFIG_FILE, LOCAL_CONFIG_FILENAME = ".claudish.json", DEFAULT_CONFIG, defaultScopedConfigPaths;
|
|
18978
19102
|
var init_profile_config = __esm(() => {
|
|
18979
|
-
CONFIG_DIR =
|
|
18980
|
-
CONFIG_FILE =
|
|
19103
|
+
CONFIG_DIR = join9(homedir9(), ".claudish");
|
|
19104
|
+
CONFIG_FILE = join9(CONFIG_DIR, "config.json");
|
|
18981
19105
|
DEFAULT_CONFIG = {
|
|
18982
19106
|
version: "1.0.0",
|
|
18983
19107
|
defaultProfile: "default",
|
|
@@ -21200,10 +21324,34 @@ function keepOnlyRealTools(extracted, knownToolNames, decodeToolName) {
|
|
|
21200
21324
|
}
|
|
21201
21325
|
return kept;
|
|
21202
21326
|
}
|
|
21327
|
+
function unwrapToolCallTags(body) {
|
|
21328
|
+
if (!body.startsWith("<tool_call>"))
|
|
21329
|
+
return null;
|
|
21330
|
+
const blocks = [];
|
|
21331
|
+
let cursor = 0;
|
|
21332
|
+
while (cursor < body.length) {
|
|
21333
|
+
TOOL_CALL_OPEN_AT_CURSOR.lastIndex = cursor;
|
|
21334
|
+
if (!TOOL_CALL_OPEN_AT_CURSOR.exec(body))
|
|
21335
|
+
return null;
|
|
21336
|
+
cursor = TOOL_CALL_OPEN_AT_CURSOR.lastIndex;
|
|
21337
|
+
const close = body.indexOf(TOOL_CALL_CLOSE_TAG, cursor);
|
|
21338
|
+
const block = (close === -1 ? body.slice(cursor) : body.slice(cursor, close)).trim();
|
|
21339
|
+
if (!block.startsWith("<function="))
|
|
21340
|
+
return null;
|
|
21341
|
+
blocks.push(block);
|
|
21342
|
+
if (close === -1)
|
|
21343
|
+
break;
|
|
21344
|
+
cursor = close + TOOL_CALL_CLOSE_TAG.length;
|
|
21345
|
+
cursor += /^\s*/.exec(body.slice(cursor))?.[0].length ?? 0;
|
|
21346
|
+
}
|
|
21347
|
+
return blocks.length > 0 ? blocks.join(`
|
|
21348
|
+
`) : null;
|
|
21349
|
+
}
|
|
21203
21350
|
function parseFunctionTagEnvelope(text) {
|
|
21204
|
-
const
|
|
21205
|
-
if (
|
|
21351
|
+
const trimmed = text.trim();
|
|
21352
|
+
if (trimmed.length === 0)
|
|
21206
21353
|
return null;
|
|
21354
|
+
const body = unwrapToolCallTags(trimmed) ?? trimmed;
|
|
21207
21355
|
if (!body.startsWith("<function="))
|
|
21208
21356
|
return null;
|
|
21209
21357
|
const calls = [];
|
|
@@ -21440,7 +21588,7 @@ function validateAndRepairToolCall(toolName, argsStr, toolSchemas, textContent)
|
|
|
21440
21588
|
}
|
|
21441
21589
|
return { valid: false, args, repaired: false, missingParams };
|
|
21442
21590
|
}
|
|
21443
|
-
var FUNCTION_TAG_SOURCE, FUNCTION_TAG_PRESENT, FUNCTION_TAG_AT_CURSOR, PARAMETER_TAG_AT_CURSOR;
|
|
21591
|
+
var FUNCTION_TAG_SOURCE, FUNCTION_TAG_PRESENT, FUNCTION_TAG_AT_CURSOR, PARAMETER_TAG_AT_CURSOR, TOOL_CALL_OPEN_AT_CURSOR, TOOL_CALL_CLOSE_TAG = "</tool_call>";
|
|
21444
21592
|
var init_tool_call_recovery = __esm(() => {
|
|
21445
21593
|
init_tool_name_utils();
|
|
21446
21594
|
init_logger();
|
|
@@ -21449,6 +21597,7 @@ var init_tool_call_recovery = __esm(() => {
|
|
|
21449
21597
|
FUNCTION_TAG_PRESENT = new RegExp(`<function=${TOOL_NAME_SOURCE}>`);
|
|
21450
21598
|
FUNCTION_TAG_AT_CURSOR = new RegExp(`<function=(${TOOL_NAME_SOURCE})>`, "y");
|
|
21451
21599
|
PARAMETER_TAG_AT_CURSOR = /<parameter=([^>\s]+)>/y;
|
|
21600
|
+
TOOL_CALL_OPEN_AT_CURSOR = /<tool_call>\s*/y;
|
|
21452
21601
|
});
|
|
21453
21602
|
|
|
21454
21603
|
// src/handlers/shared/web-search-detector.ts
|
|
@@ -22859,9 +23008,9 @@ var init_openai_api_format = __esm(() => {
|
|
|
22859
23008
|
|
|
22860
23009
|
// src/auth/vertex-auth.ts
|
|
22861
23010
|
import { exec } from "child_process";
|
|
22862
|
-
import { existsSync as
|
|
22863
|
-
import { homedir as
|
|
22864
|
-
import { join as
|
|
23011
|
+
import { existsSync as existsSync8 } from "fs";
|
|
23012
|
+
import { homedir as homedir10 } from "os";
|
|
23013
|
+
import { join as join10 } from "path";
|
|
22865
23014
|
import { promisify } from "util";
|
|
22866
23015
|
|
|
22867
23016
|
class VertexAuthManager {
|
|
@@ -22916,8 +23065,8 @@ class VertexAuthManager {
|
|
|
22916
23065
|
}
|
|
22917
23066
|
async tryADC() {
|
|
22918
23067
|
try {
|
|
22919
|
-
const adcPath =
|
|
22920
|
-
if (!
|
|
23068
|
+
const adcPath = join10(homedir10(), ".config/gcloud/application_default_credentials.json");
|
|
23069
|
+
if (!existsSync8(adcPath)) {
|
|
22921
23070
|
log("[VertexAuth] ADC credentials file not found");
|
|
22922
23071
|
return null;
|
|
22923
23072
|
}
|
|
@@ -22941,7 +23090,7 @@ class VertexAuthManager {
|
|
|
22941
23090
|
if (!credPath) {
|
|
22942
23091
|
return null;
|
|
22943
23092
|
}
|
|
22944
|
-
if (!
|
|
23093
|
+
if (!existsSync8(credPath)) {
|
|
22945
23094
|
throw new Error(`Service account file not found: ${credPath}
|
|
22946
23095
|
|
|
22947
23096
|
Check GOOGLE_APPLICATION_CREDENTIALS path.`);
|
|
@@ -22980,8 +23129,8 @@ function validateVertexOAuthConfig() {
|
|
|
22980
23129
|
` + ` export VERTEX_PROJECT='your-gcp-project-id'
|
|
22981
23130
|
` + " export VERTEX_LOCATION='us-central1' # optional";
|
|
22982
23131
|
}
|
|
22983
|
-
const adcPath =
|
|
22984
|
-
const hasADC =
|
|
23132
|
+
const adcPath = join10(homedir10(), ".config/gcloud/application_default_credentials.json");
|
|
23133
|
+
const hasADC = existsSync8(adcPath);
|
|
22985
23134
|
const hasServiceAccount = !!process.env.GOOGLE_APPLICATION_CREDENTIALS;
|
|
22986
23135
|
if (!hasADC && !hasServiceAccount) {
|
|
22987
23136
|
return `No Vertex AI credentials found.
|
|
@@ -23591,9 +23740,9 @@ var init_dialect_manager = __esm(() => {
|
|
|
23591
23740
|
|
|
23592
23741
|
// src/auth/antigravity-token.ts
|
|
23593
23742
|
import { execFileSync } from "child_process";
|
|
23594
|
-
import { existsSync as
|
|
23595
|
-
import { homedir as
|
|
23596
|
-
import { join as
|
|
23743
|
+
import { existsSync as existsSync9 } from "fs";
|
|
23744
|
+
import { homedir as homedir11 } from "os";
|
|
23745
|
+
import { join as join11 } from "path";
|
|
23597
23746
|
function invalidateReadStoreMemo() {
|
|
23598
23747
|
cachedRawStore = null;
|
|
23599
23748
|
}
|
|
@@ -23629,8 +23778,8 @@ function locateAgyBinary() {
|
|
|
23629
23778
|
if (p.length > 0)
|
|
23630
23779
|
return p;
|
|
23631
23780
|
} catch {}
|
|
23632
|
-
const fallback =
|
|
23633
|
-
return
|
|
23781
|
+
const fallback = join11(homedir11(), ".local", "bin", "agy");
|
|
23782
|
+
return existsSync9(fallback) ? fallback : null;
|
|
23634
23783
|
}
|
|
23635
23784
|
function defaultDeleteStore() {
|
|
23636
23785
|
if (process.platform !== "darwin")
|
|
@@ -24117,9 +24266,9 @@ var init_antigravity = __esm(() => {
|
|
|
24117
24266
|
});
|
|
24118
24267
|
|
|
24119
24268
|
// src/auth/quota/sources/codex.ts
|
|
24120
|
-
import { existsSync as
|
|
24121
|
-
import { homedir as
|
|
24122
|
-
import { join as
|
|
24269
|
+
import { existsSync as existsSync10, readFileSync as readFileSync8 } from "fs";
|
|
24270
|
+
import { homedir as homedir12 } from "os";
|
|
24271
|
+
import { join as join12 } from "path";
|
|
24123
24272
|
function formatWindowMinutes(minutes) {
|
|
24124
24273
|
if (!Number.isFinite(minutes) || minutes <= 0)
|
|
24125
24274
|
return "";
|
|
@@ -24133,7 +24282,7 @@ function formatWindowMinutes(minutes) {
|
|
|
24133
24282
|
return `${hours}h${minutes % 60}m`;
|
|
24134
24283
|
}
|
|
24135
24284
|
function credentialsPath() {
|
|
24136
|
-
return
|
|
24285
|
+
return join12(homedir12(), ".claudish", "codex-oauth.json");
|
|
24137
24286
|
}
|
|
24138
24287
|
function planLabel(planType) {
|
|
24139
24288
|
if (!planType)
|
|
@@ -24185,10 +24334,10 @@ function scrapeCodexHeaders(headers) {
|
|
|
24185
24334
|
}
|
|
24186
24335
|
function resolveProbeModel() {
|
|
24187
24336
|
try {
|
|
24188
|
-
const cachePath =
|
|
24189
|
-
if (!
|
|
24337
|
+
const cachePath = join12(homedir12(), ".codex", "models_cache.json");
|
|
24338
|
+
if (!existsSync10(cachePath))
|
|
24190
24339
|
return;
|
|
24191
|
-
const cache = JSON.parse(
|
|
24340
|
+
const cache = JSON.parse(readFileSync8(cachePath, "utf-8"));
|
|
24192
24341
|
for (const m of cache.models ?? []) {
|
|
24193
24342
|
const slug = m?.slug ?? m?.id;
|
|
24194
24343
|
if (typeof slug === "string" && slug.length > 0)
|
|
@@ -24200,9 +24349,9 @@ function resolveProbeModel() {
|
|
|
24200
24349
|
function readCodexCredentials() {
|
|
24201
24350
|
try {
|
|
24202
24351
|
const path = credentialsPath();
|
|
24203
|
-
if (!
|
|
24352
|
+
if (!existsSync10(path))
|
|
24204
24353
|
return;
|
|
24205
|
-
return JSON.parse(
|
|
24354
|
+
return JSON.parse(readFileSync8(path, "utf-8"));
|
|
24206
24355
|
} catch {
|
|
24207
24356
|
return;
|
|
24208
24357
|
}
|
|
@@ -24233,7 +24382,7 @@ var init_codex = __esm(() => {
|
|
|
24233
24382
|
},
|
|
24234
24383
|
isAvailable() {
|
|
24235
24384
|
try {
|
|
24236
|
-
return
|
|
24385
|
+
return existsSync10(credentialsPath());
|
|
24237
24386
|
} catch {
|
|
24238
24387
|
return false;
|
|
24239
24388
|
}
|
|
@@ -24287,15 +24436,15 @@ import { exec as exec2 } from "child_process";
|
|
|
24287
24436
|
import { createHash as createHash2, randomBytes } from "crypto";
|
|
24288
24437
|
import {
|
|
24289
24438
|
closeSync as closeSync2,
|
|
24290
|
-
existsSync as
|
|
24291
|
-
mkdirSync as
|
|
24439
|
+
existsSync as existsSync11,
|
|
24440
|
+
mkdirSync as mkdirSync8,
|
|
24292
24441
|
openSync as openSync2,
|
|
24293
|
-
readFileSync as
|
|
24442
|
+
readFileSync as readFileSync9,
|
|
24294
24443
|
unlinkSync as unlinkSync2,
|
|
24295
24444
|
writeSync as writeSync2
|
|
24296
24445
|
} from "fs";
|
|
24297
|
-
import { homedir as
|
|
24298
|
-
import { join as
|
|
24446
|
+
import { homedir as homedir13 } from "os";
|
|
24447
|
+
import { join as join13 } from "path";
|
|
24299
24448
|
import { promisify as promisify2 } from "util";
|
|
24300
24449
|
|
|
24301
24450
|
class OAuthManager {
|
|
@@ -24303,21 +24452,21 @@ class OAuthManager {
|
|
|
24303
24452
|
refreshPromise = null;
|
|
24304
24453
|
tokenRefreshMargin = 5 * 60 * 1000;
|
|
24305
24454
|
static ensureClaudishDir() {
|
|
24306
|
-
const dir =
|
|
24307
|
-
if (!
|
|
24308
|
-
|
|
24455
|
+
const dir = join13(homedir13(), ".claudish");
|
|
24456
|
+
if (!existsSync11(dir)) {
|
|
24457
|
+
mkdirSync8(dir, { recursive: true });
|
|
24309
24458
|
}
|
|
24310
24459
|
return dir;
|
|
24311
24460
|
}
|
|
24312
24461
|
getCredentialsPath() {
|
|
24313
|
-
return
|
|
24462
|
+
return join13(homedir13(), ".claudish", this.credentialFile);
|
|
24314
24463
|
}
|
|
24315
24464
|
loadCredentials() {
|
|
24316
24465
|
const credPath = this.getCredentialsPath();
|
|
24317
|
-
if (!
|
|
24466
|
+
if (!existsSync11(credPath))
|
|
24318
24467
|
return null;
|
|
24319
24468
|
try {
|
|
24320
|
-
const data = JSON.parse(
|
|
24469
|
+
const data = JSON.parse(readFileSync9(credPath, "utf-8"));
|
|
24321
24470
|
if (!this.validateCredentials(data)) {
|
|
24322
24471
|
log(`[${this.providerName}] Invalid credentials file structure`);
|
|
24323
24472
|
return null;
|
|
@@ -24342,7 +24491,7 @@ class OAuthManager {
|
|
|
24342
24491
|
}
|
|
24343
24492
|
deleteCredentials() {
|
|
24344
24493
|
const credPath = this.getCredentialsPath();
|
|
24345
|
-
if (
|
|
24494
|
+
if (existsSync11(credPath)) {
|
|
24346
24495
|
unlinkSync2(credPath);
|
|
24347
24496
|
log(`[${this.providerName}] Credentials deleted`);
|
|
24348
24497
|
}
|
|
@@ -24649,14 +24798,14 @@ Signed in to Grok. Try it with: claudish --model gk@grok-4.6 "hello"
|
|
|
24649
24798
|
});
|
|
24650
24799
|
|
|
24651
24800
|
// src/providers/grok/grok-credentials.ts
|
|
24652
|
-
import { existsSync as
|
|
24653
|
-
import { homedir as
|
|
24654
|
-
import { join as
|
|
24801
|
+
import { existsSync as existsSync12, readFileSync as readFileSync10, renameSync, writeFileSync as writeFileSync8 } from "fs";
|
|
24802
|
+
import { homedir as homedir14 } from "os";
|
|
24803
|
+
import { join as join14 } from "path";
|
|
24655
24804
|
function grokHome() {
|
|
24656
|
-
return grokHomeOverride ??
|
|
24805
|
+
return grokHomeOverride ?? join14(homedir14(), ".grok");
|
|
24657
24806
|
}
|
|
24658
24807
|
function grokAuthPath() {
|
|
24659
|
-
return
|
|
24808
|
+
return join14(grokHome(), "auth.json");
|
|
24660
24809
|
}
|
|
24661
24810
|
function str(value) {
|
|
24662
24811
|
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
@@ -24664,7 +24813,7 @@ function str(value) {
|
|
|
24664
24813
|
function readGrokCredential() {
|
|
24665
24814
|
let parsed;
|
|
24666
24815
|
try {
|
|
24667
|
-
parsed = JSON.parse(
|
|
24816
|
+
parsed = JSON.parse(readFileSync10(grokAuthPath(), "utf8"));
|
|
24668
24817
|
} catch {
|
|
24669
24818
|
return;
|
|
24670
24819
|
}
|
|
@@ -24689,10 +24838,10 @@ function readGrokCredential() {
|
|
|
24689
24838
|
};
|
|
24690
24839
|
}
|
|
24691
24840
|
function claudishGrokOAuthPath() {
|
|
24692
|
-
return claudishOAuthPathOverride ??
|
|
24841
|
+
return claudishOAuthPathOverride ?? join14(homedir14(), ".claudish", "grok-oauth.json");
|
|
24693
24842
|
}
|
|
24694
24843
|
function hasClaudishGrokOAuth() {
|
|
24695
|
-
return
|
|
24844
|
+
return existsSync12(claudishGrokOAuthPath());
|
|
24696
24845
|
}
|
|
24697
24846
|
function hasGrokCredentials() {
|
|
24698
24847
|
return hasClaudishGrokOAuth() || readGrokCredential() !== undefined;
|
|
@@ -24714,7 +24863,7 @@ function readLocalGrokVersion() {
|
|
|
24714
24863
|
["models_cache.json", "grok_version"]
|
|
24715
24864
|
]) {
|
|
24716
24865
|
try {
|
|
24717
|
-
const parsed = JSON.parse(
|
|
24866
|
+
const parsed = JSON.parse(readFileSync10(join14(grokHome(), file), "utf8"));
|
|
24718
24867
|
const version = str(parsed[field]);
|
|
24719
24868
|
if (version)
|
|
24720
24869
|
return version;
|
|
@@ -24760,7 +24909,7 @@ function persistRefreshedToken(scope, next) {
|
|
|
24760
24909
|
const path = grokAuthPath();
|
|
24761
24910
|
let parsed;
|
|
24762
24911
|
try {
|
|
24763
|
-
parsed = JSON.parse(
|
|
24912
|
+
parsed = JSON.parse(readFileSync10(path, "utf8"));
|
|
24764
24913
|
} catch {
|
|
24765
24914
|
return;
|
|
24766
24915
|
}
|
|
@@ -24773,7 +24922,7 @@ function persistRefreshedToken(scope, next) {
|
|
|
24773
24922
|
if (next.expiresAt)
|
|
24774
24923
|
entry.expires_at = next.expiresAt;
|
|
24775
24924
|
const tmp = `${path}.claudish.tmp`;
|
|
24776
|
-
|
|
24925
|
+
writeFileSync8(tmp, `${JSON.stringify(parsed, null, 2)}
|
|
24777
24926
|
`, { mode: 384 });
|
|
24778
24927
|
renameSync(tmp, path);
|
|
24779
24928
|
}
|
|
@@ -25303,8 +25452,8 @@ var init_harness = __esm(() => {
|
|
|
25303
25452
|
|
|
25304
25453
|
// src/behavior/journal.ts
|
|
25305
25454
|
import { appendFile as appendFile2, mkdir, readFile, rename, stat, writeFile } from "fs/promises";
|
|
25306
|
-
import { homedir as
|
|
25307
|
-
import { dirname as
|
|
25455
|
+
import { homedir as homedir15 } from "os";
|
|
25456
|
+
import { dirname as dirname7, join as join15 } from "path";
|
|
25308
25457
|
function classifyPath(observed, expected) {
|
|
25309
25458
|
if (!observed)
|
|
25310
25459
|
return "not_applicable";
|
|
@@ -25316,7 +25465,7 @@ function classifyPath(observed, expected) {
|
|
|
25316
25465
|
return dirOf(observed) === dirOf(expected) ? "same_dir_wrong_name" : "outside_expected_dir";
|
|
25317
25466
|
}
|
|
25318
25467
|
function journalPath() {
|
|
25319
|
-
return
|
|
25468
|
+
return join15(homedir15(), ".claudish", "behavior-journal.jsonl");
|
|
25320
25469
|
}
|
|
25321
25470
|
async function prune(path) {
|
|
25322
25471
|
const content = await readFile(path, "utf8");
|
|
@@ -25343,7 +25492,7 @@ async function recordDecision(entry, path = journalPath()) {
|
|
|
25343
25492
|
try {
|
|
25344
25493
|
const size = await stat(path).then((s) => s.size, () => 0);
|
|
25345
25494
|
if (size === 0)
|
|
25346
|
-
await mkdir(
|
|
25495
|
+
await mkdir(dirname7(path), { recursive: true }).catch(() => {});
|
|
25347
25496
|
if (size > MAX_JOURNAL_BYTES) {
|
|
25348
25497
|
await prune(path).catch((err) => log(`[behavior:journal] prune failed: ${err}`));
|
|
25349
25498
|
}
|
|
@@ -25362,9 +25511,9 @@ var init_journal = __esm(() => {
|
|
|
25362
25511
|
|
|
25363
25512
|
// src/behavior/telemetry/aggregate.ts
|
|
25364
25513
|
import { createHash as createHash3, randomBytes as randomBytes2 } from "crypto";
|
|
25365
|
-
import { appendFileSync as appendFileSync2, mkdirSync as
|
|
25366
|
-
import { homedir as
|
|
25367
|
-
import { dirname as
|
|
25514
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync9 } from "fs";
|
|
25515
|
+
import { homedir as homedir16 } from "os";
|
|
25516
|
+
import { dirname as dirname8, join as join16 } from "path";
|
|
25368
25517
|
function contextBucket(inputTokens) {
|
|
25369
25518
|
if (inputTokens < 50000)
|
|
25370
25519
|
return "0-50k";
|
|
@@ -25478,7 +25627,7 @@ function pendingReports() {
|
|
|
25478
25627
|
return [...sessions.values()].map(toReport);
|
|
25479
25628
|
}
|
|
25480
25629
|
function outboxPath() {
|
|
25481
|
-
return
|
|
25630
|
+
return join16(homedir16(), ".claudish", "behavior-outbox.jsonl");
|
|
25482
25631
|
}
|
|
25483
25632
|
function spoolPendingSync(path = outboxPath()) {
|
|
25484
25633
|
if (sessions.size === 0)
|
|
@@ -25488,7 +25637,7 @@ function spoolPendingSync(path = outboxPath()) {
|
|
|
25488
25637
|
if (reports.length === 0)
|
|
25489
25638
|
return 0;
|
|
25490
25639
|
try {
|
|
25491
|
-
|
|
25640
|
+
mkdirSync9(dirname8(path), { recursive: true });
|
|
25492
25641
|
appendFileSync2(path, `${reports.map((r) => JSON.stringify(r)).join(`
|
|
25493
25642
|
`)}
|
|
25494
25643
|
`);
|
|
@@ -25685,10 +25834,10 @@ var init_client = __esm(() => {
|
|
|
25685
25834
|
|
|
25686
25835
|
// src/behavior/observer/live-log.ts
|
|
25687
25836
|
import { appendFile as appendFile3 } from "fs/promises";
|
|
25688
|
-
import { homedir as
|
|
25689
|
-
import { join as
|
|
25837
|
+
import { homedir as homedir17 } from "os";
|
|
25838
|
+
import { join as join17 } from "path";
|
|
25690
25839
|
function defaultPath() {
|
|
25691
|
-
return
|
|
25840
|
+
return join17(homedir17(), ".claudish", "behavior-divergences.jsonl");
|
|
25692
25841
|
}
|
|
25693
25842
|
async function recordLiveDivergence(entry, path = defaultPath()) {
|
|
25694
25843
|
try {
|
|
@@ -26376,9 +26525,9 @@ var init_hooks = __esm(() => {
|
|
|
26376
26525
|
});
|
|
26377
26526
|
|
|
26378
26527
|
// src/behavior/observer/corpus.ts
|
|
26379
|
-
import { appendFileSync as appendFileSync3, readFileSync as
|
|
26380
|
-
import { homedir as
|
|
26381
|
-
import { join as
|
|
26528
|
+
import { appendFileSync as appendFileSync3, readFileSync as readFileSync11, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
|
|
26529
|
+
import { homedir as homedir18 } from "os";
|
|
26530
|
+
import { join as join18 } from "path";
|
|
26382
26531
|
function directoryOf2(filePath) {
|
|
26383
26532
|
const slash = filePath.lastIndexOf("/");
|
|
26384
26533
|
return slash > 0 ? filePath.slice(0, slash) : undefined;
|
|
@@ -26400,7 +26549,7 @@ function writeTargetsOf(row) {
|
|
|
26400
26549
|
function replayTranscript(file) {
|
|
26401
26550
|
let text;
|
|
26402
26551
|
try {
|
|
26403
|
-
text =
|
|
26552
|
+
text = readFileSync11(file, "utf8");
|
|
26404
26553
|
} catch {
|
|
26405
26554
|
return [];
|
|
26406
26555
|
}
|
|
@@ -26457,26 +26606,26 @@ function listTranscripts(root) {
|
|
|
26457
26606
|
return files;
|
|
26458
26607
|
}
|
|
26459
26608
|
for (const project of projects) {
|
|
26460
|
-
const dir =
|
|
26609
|
+
const dir = join18(root, project);
|
|
26461
26610
|
try {
|
|
26462
26611
|
if (!statSync2(dir).isDirectory())
|
|
26463
26612
|
continue;
|
|
26464
26613
|
for (const f of readdirSync2(dir)) {
|
|
26465
26614
|
if (f.endsWith(".jsonl"))
|
|
26466
|
-
files.push(
|
|
26615
|
+
files.push(join18(dir, f));
|
|
26467
26616
|
}
|
|
26468
26617
|
} catch {}
|
|
26469
26618
|
}
|
|
26470
26619
|
return files;
|
|
26471
26620
|
}
|
|
26472
26621
|
function buildCorpus(options = {}) {
|
|
26473
|
-
const root = options.projectsRoot ??
|
|
26622
|
+
const root = options.projectsRoot ?? join18(homedir18(), ".claude", "projects");
|
|
26474
26623
|
const files = listTranscripts(root);
|
|
26475
26624
|
const records = [];
|
|
26476
26625
|
for (const f of files)
|
|
26477
26626
|
records.push(...replayTranscript(f));
|
|
26478
26627
|
if (options.write && records.length > 0) {
|
|
26479
|
-
const outputPath = options.outputPath ??
|
|
26628
|
+
const outputPath = options.outputPath ?? join18(homedir18(), ".claudish", "behavior-divergences.jsonl");
|
|
26480
26629
|
try {
|
|
26481
26630
|
appendFileSync3(outputPath, `${records.map((r) => JSON.stringify(r)).join(`
|
|
26482
26631
|
`)}
|
|
@@ -27853,9 +28002,9 @@ var init_keychain_source = __esm(() => {
|
|
|
27853
28002
|
});
|
|
27854
28003
|
|
|
27855
28004
|
// src/auth/credentials/api-key-credential.ts
|
|
27856
|
-
import { existsSync as
|
|
27857
|
-
import { homedir as
|
|
27858
|
-
import { join as
|
|
28005
|
+
import { existsSync as existsSync13 } from "fs";
|
|
28006
|
+
import { homedir as homedir19 } from "os";
|
|
28007
|
+
import { join as join19 } from "path";
|
|
27859
28008
|
|
|
27860
28009
|
class ApiKeyCredentialProvider {
|
|
27861
28010
|
catalogName;
|
|
@@ -27890,7 +28039,7 @@ class ApiKeyCredentialProvider {
|
|
|
27890
28039
|
if (!this.oauthFallback)
|
|
27891
28040
|
return false;
|
|
27892
28041
|
try {
|
|
27893
|
-
return
|
|
28042
|
+
return existsSync13(join19(homedir19(), ".claudish", this.oauthFallback));
|
|
27894
28043
|
} catch {
|
|
27895
28044
|
return false;
|
|
27896
28045
|
}
|
|
@@ -27981,10 +28130,10 @@ var init_api_key_credential = __esm(() => {
|
|
|
27981
28130
|
// src/auth/codex-oauth.ts
|
|
27982
28131
|
import { exec as exec3 } from "child_process";
|
|
27983
28132
|
import { createHash as createHash4, randomBytes as randomBytes3 } from "crypto";
|
|
27984
|
-
import { closeSync as closeSync3, existsSync as
|
|
28133
|
+
import { closeSync as closeSync3, existsSync as existsSync14, openSync as openSync3, readFileSync as readFileSync12, unlinkSync as unlinkSync3, writeSync as writeSync3 } from "fs";
|
|
27985
28134
|
import { createServer } from "http";
|
|
27986
|
-
import { homedir as
|
|
27987
|
-
import { join as
|
|
28135
|
+
import { homedir as homedir20 } from "os";
|
|
28136
|
+
import { join as join20 } from "path";
|
|
27988
28137
|
import { promisify as promisify3 } from "util";
|
|
27989
28138
|
|
|
27990
28139
|
class CodexOAuth {
|
|
@@ -28010,8 +28159,8 @@ class CodexOAuth {
|
|
|
28010
28159
|
return this.credentials !== null && !!this.credentials.refresh_token;
|
|
28011
28160
|
}
|
|
28012
28161
|
getCredentialsPath() {
|
|
28013
|
-
const claudishDir =
|
|
28014
|
-
return
|
|
28162
|
+
const claudishDir = join20(homedir20(), ".claudish");
|
|
28163
|
+
return join20(claudishDir, "codex-oauth.json");
|
|
28015
28164
|
}
|
|
28016
28165
|
async login() {
|
|
28017
28166
|
log("[CodexOAuth] Starting OAuth login flow");
|
|
@@ -28037,7 +28186,7 @@ class CodexOAuth {
|
|
|
28037
28186
|
}
|
|
28038
28187
|
async logout() {
|
|
28039
28188
|
const credPath = this.getCredentialsPath();
|
|
28040
|
-
if (
|
|
28189
|
+
if (existsSync14(credPath)) {
|
|
28041
28190
|
unlinkSync3(credPath);
|
|
28042
28191
|
log("[CodexOAuth] Credentials deleted");
|
|
28043
28192
|
}
|
|
@@ -28115,11 +28264,11 @@ Details: ${e.message}`);
|
|
|
28115
28264
|
}
|
|
28116
28265
|
loadCredentials() {
|
|
28117
28266
|
const credPath = this.getCredentialsPath();
|
|
28118
|
-
if (!
|
|
28267
|
+
if (!existsSync14(credPath)) {
|
|
28119
28268
|
return null;
|
|
28120
28269
|
}
|
|
28121
28270
|
try {
|
|
28122
|
-
const data =
|
|
28271
|
+
const data = readFileSync12(credPath, "utf-8");
|
|
28123
28272
|
const credentials = JSON.parse(data);
|
|
28124
28273
|
if (!credentials.access_token || !credentials.refresh_token || !credentials.expires_at) {
|
|
28125
28274
|
log("[CodexOAuth] Invalid credentials file structure");
|
|
@@ -28134,8 +28283,8 @@ Details: ${e.message}`);
|
|
|
28134
28283
|
}
|
|
28135
28284
|
saveCredentials(credentials) {
|
|
28136
28285
|
const credPath = this.getCredentialsPath();
|
|
28137
|
-
const claudishDir =
|
|
28138
|
-
if (!
|
|
28286
|
+
const claudishDir = join20(homedir20(), ".claudish");
|
|
28287
|
+
if (!existsSync14(claudishDir)) {
|
|
28139
28288
|
const { mkdirSync } = __require("fs");
|
|
28140
28289
|
mkdirSync(claudishDir, { recursive: true });
|
|
28141
28290
|
}
|
|
@@ -28472,11 +28621,11 @@ var init_codex_credential = __esm(() => {
|
|
|
28472
28621
|
});
|
|
28473
28622
|
|
|
28474
28623
|
// src/providers/devin/devin-credentials.ts
|
|
28475
|
-
import { readFileSync as
|
|
28476
|
-
import { homedir as
|
|
28477
|
-
import { join as
|
|
28624
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
28625
|
+
import { homedir as homedir21 } from "os";
|
|
28626
|
+
import { join as join21 } from "path";
|
|
28478
28627
|
function devinCredentialsPath() {
|
|
28479
|
-
return credentialsPathOverride ??
|
|
28628
|
+
return credentialsPathOverride ?? join21(homedir21(), ".local", "share", "devin", "credentials.toml");
|
|
28480
28629
|
}
|
|
28481
28630
|
function readTomlString(source, key) {
|
|
28482
28631
|
const match = source.match(new RegExp(`^\\s*${key}\\s*=\\s*"([^"]*)"`, "m"));
|
|
@@ -28489,7 +28638,7 @@ function readCredentialsFile() {
|
|
|
28489
28638
|
return fileCache.value;
|
|
28490
28639
|
let value = {};
|
|
28491
28640
|
try {
|
|
28492
|
-
const source =
|
|
28641
|
+
const source = readFileSync13(path, "utf8");
|
|
28493
28642
|
value = {
|
|
28494
28643
|
apiKey: readTomlString(source, "windsurf_api_key"),
|
|
28495
28644
|
serverUrl: readTomlString(source, "api_server_url")
|
|
@@ -28578,9 +28727,9 @@ var init_grok_credential = __esm(() => {
|
|
|
28578
28727
|
// src/auth/kimi-oauth.ts
|
|
28579
28728
|
import { exec as exec4 } from "child_process";
|
|
28580
28729
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
28581
|
-
import { closeSync as closeSync4, existsSync as
|
|
28582
|
-
import { homedir as
|
|
28583
|
-
import { join as
|
|
28730
|
+
import { closeSync as closeSync4, existsSync as existsSync15, openSync as openSync4, readFileSync as readFileSync14, unlinkSync as unlinkSync4, writeSync as writeSync4 } from "fs";
|
|
28731
|
+
import { homedir as homedir22, hostname, platform, release as release2 } from "os";
|
|
28732
|
+
import { join as join22 } from "path";
|
|
28584
28733
|
import { promisify as promisify4 } from "util";
|
|
28585
28734
|
|
|
28586
28735
|
class KimiOAuth {
|
|
@@ -28608,23 +28757,23 @@ class KimiOAuth {
|
|
|
28608
28757
|
return this.credentials !== null && !!this.credentials.refresh_token;
|
|
28609
28758
|
}
|
|
28610
28759
|
getCredentialsPath() {
|
|
28611
|
-
const claudishDir =
|
|
28612
|
-
return
|
|
28760
|
+
const claudishDir = join22(homedir22(), ".claudish");
|
|
28761
|
+
return join22(claudishDir, "kimi-oauth.json");
|
|
28613
28762
|
}
|
|
28614
28763
|
getDeviceIdPath() {
|
|
28615
|
-
const claudishDir =
|
|
28616
|
-
return
|
|
28764
|
+
const claudishDir = join22(homedir22(), ".claudish");
|
|
28765
|
+
return join22(claudishDir, "kimi-device-id");
|
|
28617
28766
|
}
|
|
28618
28767
|
loadOrCreateDeviceId() {
|
|
28619
28768
|
const deviceIdPath = this.getDeviceIdPath();
|
|
28620
|
-
const claudishDir =
|
|
28621
|
-
if (!
|
|
28769
|
+
const claudishDir = join22(homedir22(), ".claudish");
|
|
28770
|
+
if (!existsSync15(claudishDir)) {
|
|
28622
28771
|
const { mkdirSync } = __require("fs");
|
|
28623
28772
|
mkdirSync(claudishDir, { recursive: true });
|
|
28624
28773
|
}
|
|
28625
|
-
if (
|
|
28774
|
+
if (existsSync15(deviceIdPath)) {
|
|
28626
28775
|
try {
|
|
28627
|
-
const deviceId =
|
|
28776
|
+
const deviceId = readFileSync14(deviceIdPath, "utf-8").trim();
|
|
28628
28777
|
if (deviceId) {
|
|
28629
28778
|
return deviceId;
|
|
28630
28779
|
}
|
|
@@ -28795,7 +28944,7 @@ Waiting for authorization...`);
|
|
|
28795
28944
|
}
|
|
28796
28945
|
async logout() {
|
|
28797
28946
|
const credPath = this.getCredentialsPath();
|
|
28798
|
-
if (
|
|
28947
|
+
if (existsSync15(credPath)) {
|
|
28799
28948
|
unlinkSync4(credPath);
|
|
28800
28949
|
log("[KimiOAuth] Credentials deleted");
|
|
28801
28950
|
}
|
|
@@ -28862,7 +29011,7 @@ Waiting for authorization...`);
|
|
|
28862
29011
|
} catch (e) {
|
|
28863
29012
|
log(`[KimiOAuth] Refresh failed: ${e.message}`);
|
|
28864
29013
|
const credPath = this.getCredentialsPath();
|
|
28865
|
-
if (
|
|
29014
|
+
if (existsSync15(credPath)) {
|
|
28866
29015
|
unlinkSync4(credPath);
|
|
28867
29016
|
}
|
|
28868
29017
|
this.credentials = null;
|
|
@@ -28879,11 +29028,11 @@ Details: ${e.message}`);
|
|
|
28879
29028
|
}
|
|
28880
29029
|
loadCredentials() {
|
|
28881
29030
|
const credPath = this.getCredentialsPath();
|
|
28882
|
-
if (!
|
|
29031
|
+
if (!existsSync15(credPath)) {
|
|
28883
29032
|
return null;
|
|
28884
29033
|
}
|
|
28885
29034
|
try {
|
|
28886
|
-
const data =
|
|
29035
|
+
const data = readFileSync14(credPath, "utf-8");
|
|
28887
29036
|
const credentials = JSON.parse(data);
|
|
28888
29037
|
if (!credentials.access_token || !credentials.refresh_token || !credentials.expires_at || !credentials.scope || !credentials.token_type) {
|
|
28889
29038
|
log("[KimiOAuth] Invalid credentials file structure");
|
|
@@ -28898,8 +29047,8 @@ Details: ${e.message}`);
|
|
|
28898
29047
|
}
|
|
28899
29048
|
saveCredentials(credentials) {
|
|
28900
29049
|
const credPath = this.getCredentialsPath();
|
|
28901
|
-
const claudishDir =
|
|
28902
|
-
if (!
|
|
29050
|
+
const claudishDir = join22(homedir22(), ".claudish");
|
|
29051
|
+
if (!existsSync15(claudishDir)) {
|
|
28903
29052
|
const { mkdirSync } = __require("fs");
|
|
28904
29053
|
mkdirSync(claudishDir, { recursive: true });
|
|
28905
29054
|
}
|
|
@@ -28929,9 +29078,9 @@ var init_kimi_oauth = __esm(() => {
|
|
|
28929
29078
|
});
|
|
28930
29079
|
|
|
28931
29080
|
// src/auth/oauth-registry.ts
|
|
28932
|
-
import { existsSync as
|
|
28933
|
-
import { homedir as
|
|
28934
|
-
import { join as
|
|
29081
|
+
import { existsSync as existsSync16, readFileSync as readFileSync15 } from "fs";
|
|
29082
|
+
import { homedir as homedir23 } from "os";
|
|
29083
|
+
import { join as join23 } from "path";
|
|
28935
29084
|
function credentialSatisfies(descriptor, data) {
|
|
28936
29085
|
if (!data?.access_token)
|
|
28937
29086
|
return false;
|
|
@@ -28944,14 +29093,14 @@ function credentialSatisfies(descriptor, data) {
|
|
|
28944
29093
|
return true;
|
|
28945
29094
|
}
|
|
28946
29095
|
function hasValidOAuthCredentials(descriptor) {
|
|
28947
|
-
const credPath =
|
|
28948
|
-
if (!
|
|
29096
|
+
const credPath = join23(homedir23(), ".claudish", descriptor.credentialFile);
|
|
29097
|
+
if (!existsSync16(credPath))
|
|
28949
29098
|
return false;
|
|
28950
29099
|
if (descriptor.validationMode === "file-exists") {
|
|
28951
29100
|
return true;
|
|
28952
29101
|
}
|
|
28953
29102
|
try {
|
|
28954
|
-
return credentialSatisfies(descriptor, JSON.parse(
|
|
29103
|
+
return credentialSatisfies(descriptor, JSON.parse(readFileSync15(credPath, "utf-8")));
|
|
28955
29104
|
} catch {
|
|
28956
29105
|
return false;
|
|
28957
29106
|
}
|
|
@@ -31037,9 +31186,9 @@ var DEFAULT_POLL_INTERVAL_MS = 250;
|
|
|
31037
31186
|
var init_transcript_tailer = () => {};
|
|
31038
31187
|
|
|
31039
31188
|
// src/session-events/index.ts
|
|
31040
|
-
import { existsSync as
|
|
31041
|
-
import { homedir as
|
|
31042
|
-
import { join as
|
|
31189
|
+
import { existsSync as existsSync17, readFileSync as readFileSync16, readdirSync as readdirSync3 } from "fs";
|
|
31190
|
+
import { homedir as homedir24 } from "os";
|
|
31191
|
+
import { join as join24 } from "path";
|
|
31043
31192
|
function extractSessionId2(metadata) {
|
|
31044
31193
|
const userId = metadata?.user_id;
|
|
31045
31194
|
if (typeof userId !== "string")
|
|
@@ -31064,7 +31213,7 @@ class SessionEventRegistry {
|
|
|
31064
31213
|
claudeHome;
|
|
31065
31214
|
pollIntervalMs;
|
|
31066
31215
|
constructor(opts = {}) {
|
|
31067
|
-
this.claudeHome = opts.claudeHome ??
|
|
31216
|
+
this.claudeHome = opts.claudeHome ?? join24(homedir24(), ".claude");
|
|
31068
31217
|
this.pollIntervalMs = opts.pollIntervalMs;
|
|
31069
31218
|
}
|
|
31070
31219
|
ensureSession(sessionId) {
|
|
@@ -31150,14 +31299,14 @@ class SessionEventRegistry {
|
|
|
31150
31299
|
}
|
|
31151
31300
|
}
|
|
31152
31301
|
locateTranscript(sessionId) {
|
|
31153
|
-
const projectsDir =
|
|
31154
|
-
const primary =
|
|
31155
|
-
if (
|
|
31302
|
+
const projectsDir = join24(this.claudeHome, "projects");
|
|
31303
|
+
const primary = join24(projectsDir, slugFromCwd(process.cwd()), `${sessionId}.jsonl`);
|
|
31304
|
+
if (existsSync17(primary))
|
|
31156
31305
|
return primary;
|
|
31157
31306
|
try {
|
|
31158
31307
|
for (const dir of readdirSync3(projectsDir)) {
|
|
31159
|
-
const candidate =
|
|
31160
|
-
if (
|
|
31308
|
+
const candidate = join24(projectsDir, dir, `${sessionId}.jsonl`);
|
|
31309
|
+
if (existsSync17(candidate))
|
|
31161
31310
|
return candidate;
|
|
31162
31311
|
}
|
|
31163
31312
|
} catch {}
|
|
@@ -31165,7 +31314,7 @@ class SessionEventRegistry {
|
|
|
31165
31314
|
}
|
|
31166
31315
|
readSettingsEffortLevel() {
|
|
31167
31316
|
try {
|
|
31168
|
-
const settings = JSON.parse(
|
|
31317
|
+
const settings = JSON.parse(readFileSync16(join24(this.claudeHome, "settings.json"), "utf-8"));
|
|
31169
31318
|
return typeof settings.effortLevel === "string" ? settings.effortLevel : undefined;
|
|
31170
31319
|
} catch {
|
|
31171
31320
|
return;
|
|
@@ -31364,25 +31513,25 @@ var init_model_parser = __esm(() => {
|
|
|
31364
31513
|
|
|
31365
31514
|
// src/stats-buffer.ts
|
|
31366
31515
|
import {
|
|
31367
|
-
existsSync as
|
|
31368
|
-
mkdirSync as
|
|
31369
|
-
readFileSync as
|
|
31516
|
+
existsSync as existsSync18,
|
|
31517
|
+
mkdirSync as mkdirSync10,
|
|
31518
|
+
readFileSync as readFileSync17,
|
|
31370
31519
|
renameSync as renameSync2,
|
|
31371
31520
|
unlinkSync as unlinkSync5,
|
|
31372
|
-
writeFileSync as
|
|
31521
|
+
writeFileSync as writeFileSync9
|
|
31373
31522
|
} from "fs";
|
|
31374
|
-
import { homedir as
|
|
31375
|
-
import { join as
|
|
31523
|
+
import { homedir as homedir25 } from "os";
|
|
31524
|
+
import { join as join25 } from "path";
|
|
31376
31525
|
function ensureDir() {
|
|
31377
|
-
if (!
|
|
31378
|
-
|
|
31526
|
+
if (!existsSync18(CLAUDISH_DIR)) {
|
|
31527
|
+
mkdirSync10(CLAUDISH_DIR, { recursive: true });
|
|
31379
31528
|
}
|
|
31380
31529
|
}
|
|
31381
31530
|
function readFromDisk() {
|
|
31382
31531
|
try {
|
|
31383
|
-
if (!
|
|
31532
|
+
if (!existsSync18(BUFFER_FILE))
|
|
31384
31533
|
return [];
|
|
31385
|
-
const raw =
|
|
31534
|
+
const raw = readFileSync17(BUFFER_FILE, "utf-8");
|
|
31386
31535
|
const parsed = JSON.parse(raw);
|
|
31387
31536
|
if (!Array.isArray(parsed.events))
|
|
31388
31537
|
return [];
|
|
@@ -31407,8 +31556,8 @@ function writeToDisk(events) {
|
|
|
31407
31556
|
ensureDir();
|
|
31408
31557
|
const trimmed = enforceSizeCap([...events]);
|
|
31409
31558
|
const payload = { version: 1, events: trimmed };
|
|
31410
|
-
const tmpFile =
|
|
31411
|
-
|
|
31559
|
+
const tmpFile = join25(CLAUDISH_DIR, `stats-buffer.tmp.${process.pid}.json`);
|
|
31560
|
+
writeFileSync9(tmpFile, JSON.stringify(payload, null, 2), "utf-8");
|
|
31412
31561
|
renameSync2(tmpFile, BUFFER_FILE);
|
|
31413
31562
|
memoryCache = trimmed;
|
|
31414
31563
|
} catch {}
|
|
@@ -31451,7 +31600,7 @@ function clearBuffer() {
|
|
|
31451
31600
|
try {
|
|
31452
31601
|
memoryCache = [];
|
|
31453
31602
|
eventsSinceLastFlush = 0;
|
|
31454
|
-
if (
|
|
31603
|
+
if (existsSync18(BUFFER_FILE)) {
|
|
31455
31604
|
unlinkSync5(BUFFER_FILE);
|
|
31456
31605
|
}
|
|
31457
31606
|
} catch {}
|
|
@@ -31480,8 +31629,8 @@ function syncFlushOnExit() {
|
|
|
31480
31629
|
var BUFFER_MAX_BYTES, CLAUDISH_DIR, BUFFER_FILE, memoryCache = null, eventsSinceLastFlush = 0, flushScheduled = false, SIGNAL_EXIT_CODE;
|
|
31481
31630
|
var init_stats_buffer = __esm(() => {
|
|
31482
31631
|
BUFFER_MAX_BYTES = 64 * 1024;
|
|
31483
|
-
CLAUDISH_DIR =
|
|
31484
|
-
BUFFER_FILE =
|
|
31632
|
+
CLAUDISH_DIR = join25(homedir25(), ".claudish");
|
|
31633
|
+
BUFFER_FILE = join25(CLAUDISH_DIR, "stats-buffer.json");
|
|
31485
31634
|
process.on("exit", syncFlushOnExit);
|
|
31486
31635
|
SIGNAL_EXIT_CODE = { SIGTERM: 143, SIGINT: 130 };
|
|
31487
31636
|
for (const signal of ["SIGTERM", "SIGINT"]) {
|
|
@@ -34600,9 +34749,9 @@ var init_openai_responses_sse = __esm(() => {
|
|
|
34600
34749
|
});
|
|
34601
34750
|
|
|
34602
34751
|
// src/handlers/shared/token-tracker.ts
|
|
34603
|
-
import { mkdirSync as
|
|
34604
|
-
import { homedir as
|
|
34605
|
-
import { dirname as
|
|
34752
|
+
import { mkdirSync as mkdirSync11, writeFileSync as writeFileSync10 } from "fs";
|
|
34753
|
+
import { homedir as homedir26 } from "os";
|
|
34754
|
+
import { dirname as dirname9, join as join26 } from "path";
|
|
34606
34755
|
function stripProviderPrefix(name) {
|
|
34607
34756
|
const at = name.indexOf("@");
|
|
34608
34757
|
return at === -1 ? name : name.slice(at + 1);
|
|
@@ -34813,9 +34962,9 @@ class TokenTracker {
|
|
|
34813
34962
|
};
|
|
34814
34963
|
}
|
|
34815
34964
|
const override = process.env.CLAUDISH_TOKEN_FILE;
|
|
34816
|
-
const outPath = override ||
|
|
34817
|
-
|
|
34818
|
-
|
|
34965
|
+
const outPath = override || join26(homedir26(), ".claudish", `tokens-${this.port}.json`);
|
|
34966
|
+
mkdirSync11(dirname9(outPath), { recursive: true });
|
|
34967
|
+
writeFileSync10(outPath, JSON.stringify(data), "utf-8");
|
|
34819
34968
|
} catch (e) {
|
|
34820
34969
|
log(`[TokenTracker] Error writing token file: ${e}`);
|
|
34821
34970
|
}
|
|
@@ -35856,11 +36005,11 @@ var init_composed_handler = __esm(() => {
|
|
|
35856
36005
|
});
|
|
35857
36006
|
|
|
35858
36007
|
// src/providers/api-key-provenance.ts
|
|
35859
|
-
import { existsSync as
|
|
35860
|
-
import { homedir as
|
|
35861
|
-
import { join as
|
|
36008
|
+
import { existsSync as existsSync19, readFileSync as readFileSync18 } from "fs";
|
|
36009
|
+
import { homedir as homedir27 } from "os";
|
|
36010
|
+
import { join as join27, resolve as resolve2 } from "path";
|
|
35862
36011
|
function activeConfigPath() {
|
|
35863
|
-
return activeGlobalConfigFile(
|
|
36012
|
+
return activeGlobalConfigFile(join27(homedir27(), ".claudish", "config.json"));
|
|
35864
36013
|
}
|
|
35865
36014
|
function configLayerLabel() {
|
|
35866
36015
|
return getConfigFileOverride() ? activeConfigPath() : "~/.claudish/config.json";
|
|
@@ -35940,9 +36089,9 @@ function formatProvenanceLog(p) {
|
|
|
35940
36089
|
function readDotenvKey(envVars) {
|
|
35941
36090
|
try {
|
|
35942
36091
|
const dotenvPath = resolve2(".env");
|
|
35943
|
-
if (!
|
|
36092
|
+
if (!existsSync19(dotenvPath))
|
|
35944
36093
|
return null;
|
|
35945
|
-
const parsed = import_dotenv.parse(
|
|
36094
|
+
const parsed = import_dotenv.parse(readFileSync18(dotenvPath, "utf-8"));
|
|
35946
36095
|
for (const v of envVars) {
|
|
35947
36096
|
if (parsed[v])
|
|
35948
36097
|
return parsed[v];
|
|
@@ -35955,9 +36104,9 @@ function readDotenvKey(envVars) {
|
|
|
35955
36104
|
function readConfigKey(envVar) {
|
|
35956
36105
|
try {
|
|
35957
36106
|
const configPath = activeConfigPath();
|
|
35958
|
-
if (!
|
|
36107
|
+
if (!existsSync19(configPath))
|
|
35959
36108
|
return null;
|
|
35960
|
-
const cfg = JSON.parse(
|
|
36109
|
+
const cfg = JSON.parse(readFileSync18(configPath, "utf-8"));
|
|
35961
36110
|
return cfg.apiKeys?.[envVar] || null;
|
|
35962
36111
|
} catch {
|
|
35963
36112
|
return null;
|
|
@@ -37778,6 +37927,8 @@ function derivePlansUrl(catalogUrl) {
|
|
|
37778
37927
|
function getCatalogEntries() {
|
|
37779
37928
|
if (_catalogEntriesForTest !== undefined)
|
|
37780
37929
|
return _catalogEntriesForTest;
|
|
37930
|
+
if (readCatalogIncompatibility())
|
|
37931
|
+
return null;
|
|
37781
37932
|
if (_memCache)
|
|
37782
37933
|
return _memCache;
|
|
37783
37934
|
const cache = readAllModelsCache();
|
|
@@ -37930,14 +38081,32 @@ async function fetchCatalogPage(url, timeoutMs) {
|
|
|
37930
38081
|
const reason = name === "TimeoutError" || name === "AbortError" ? "timeout" : "network";
|
|
37931
38082
|
return { ok: false, reason };
|
|
37932
38083
|
}
|
|
37933
|
-
if (!response.ok)
|
|
38084
|
+
if (!response.ok) {
|
|
38085
|
+
const verdict = await contractVerdictForError(response);
|
|
38086
|
+
if (verdict) {
|
|
38087
|
+
return {
|
|
38088
|
+
ok: false,
|
|
38089
|
+
reason: "incompatible",
|
|
38090
|
+
serverContractVersion: verdict.serverContractVersion
|
|
38091
|
+
};
|
|
38092
|
+
}
|
|
37934
38093
|
return { ok: false, reason: "http_error" };
|
|
38094
|
+
}
|
|
37935
38095
|
let page;
|
|
37936
38096
|
try {
|
|
37937
38097
|
page = await response.json();
|
|
37938
38098
|
} catch {
|
|
37939
38099
|
return { ok: false, reason: "network" };
|
|
37940
38100
|
}
|
|
38101
|
+
const bodyEnvelope = parseContractEnvelope(page);
|
|
38102
|
+
if (isIncompatibleContractVersion(bodyEnvelope.contractVersion)) {
|
|
38103
|
+
const verdict = recordIncompatibility(bodyEnvelope);
|
|
38104
|
+
return {
|
|
38105
|
+
ok: false,
|
|
38106
|
+
reason: "incompatible",
|
|
38107
|
+
serverContractVersion: verdict.serverContractVersion
|
|
38108
|
+
};
|
|
38109
|
+
}
|
|
37941
38110
|
const revision = response.headers.get(CATALOG_REVISION_HEADER) ?? undefined;
|
|
37942
38111
|
return { ok: true, page, revision };
|
|
37943
38112
|
}
|
|
@@ -37953,6 +38122,12 @@ async function refreshCatalog(timeoutMs, options = {}) {
|
|
|
37953
38122
|
const url = buildCatalogPageUrl(catalogUrl(), offset, CATALOG_PAGE_LIMIT, revision);
|
|
37954
38123
|
const result = await fetchCatalogPage(url, timeoutMs);
|
|
37955
38124
|
if (!result.ok) {
|
|
38125
|
+
if (result.reason === "incompatible") {
|
|
38126
|
+
return {
|
|
38127
|
+
kind: "incompatible",
|
|
38128
|
+
serverContractVersion: result.serverContractVersion
|
|
38129
|
+
};
|
|
38130
|
+
}
|
|
37956
38131
|
return {
|
|
37957
38132
|
kind: "fetch_failed",
|
|
37958
38133
|
reason: pages === 0 ? result.reason : "incomplete"
|
|
@@ -37988,6 +38163,7 @@ async function refreshCatalog(timeoutMs, options = {}) {
|
|
|
37988
38163
|
if (id)
|
|
37989
38164
|
backwardCompatModels.push({ id });
|
|
37990
38165
|
}
|
|
38166
|
+
clearCatalogIncompatibility();
|
|
37991
38167
|
_memCache = entries;
|
|
37992
38168
|
writeAllModelsCache({
|
|
37993
38169
|
entries,
|
|
@@ -37998,6 +38174,20 @@ async function refreshCatalog(timeoutMs, options = {}) {
|
|
|
37998
38174
|
_warmPromise = Promise.resolve();
|
|
37999
38175
|
return { kind: "refreshed", modelCount: entries.length, catalogRevision: revision, pages };
|
|
38000
38176
|
}
|
|
38177
|
+
async function contractVerdictForError(response) {
|
|
38178
|
+
const envelope = parseContractEnvelope(await readJsonBody(response));
|
|
38179
|
+
if (response.status === 426 || isIncompatibleContractVersion(envelope.contractVersion)) {
|
|
38180
|
+
return recordIncompatibility(envelope);
|
|
38181
|
+
}
|
|
38182
|
+
return null;
|
|
38183
|
+
}
|
|
38184
|
+
async function readJsonBody(response) {
|
|
38185
|
+
try {
|
|
38186
|
+
return await response.json();
|
|
38187
|
+
} catch {
|
|
38188
|
+
return;
|
|
38189
|
+
}
|
|
38190
|
+
}
|
|
38001
38191
|
async function fetchSubscriptionPlans(timeoutMs, revision) {
|
|
38002
38192
|
try {
|
|
38003
38193
|
const url = new URL(plansUrl());
|
|
@@ -38006,14 +38196,28 @@ async function fetchSubscriptionPlans(timeoutMs, revision) {
|
|
|
38006
38196
|
const response = await fetch(url.toString(), {
|
|
38007
38197
|
signal: AbortSignal.timeout(timeoutMs)
|
|
38008
38198
|
});
|
|
38009
|
-
if (!response.ok)
|
|
38199
|
+
if (!response.ok) {
|
|
38200
|
+
await contractVerdictForError(response);
|
|
38010
38201
|
return;
|
|
38202
|
+
}
|
|
38011
38203
|
const data = await response.json();
|
|
38204
|
+
const envelope = parseContractEnvelope(data);
|
|
38205
|
+
if (isIncompatibleContractVersion(envelope.contractVersion)) {
|
|
38206
|
+
recordIncompatibility(envelope);
|
|
38207
|
+
return;
|
|
38208
|
+
}
|
|
38012
38209
|
return Array.isArray(data.plans) ? data.plans : undefined;
|
|
38013
38210
|
} catch {
|
|
38014
38211
|
return;
|
|
38015
38212
|
}
|
|
38016
38213
|
}
|
|
38214
|
+
function recordIncompatibility(envelope) {
|
|
38215
|
+
markCatalogIncompatible({
|
|
38216
|
+
serverContractVersion: envelope.contractVersion,
|
|
38217
|
+
...envelope.minimumContractVersion !== undefined ? { minimumContractVersion: envelope.minimumContractVersion } : {}
|
|
38218
|
+
});
|
|
38219
|
+
return { kind: "incompatible", serverContractVersion: envelope.contractVersion };
|
|
38220
|
+
}
|
|
38017
38221
|
async function warmCatalog() {
|
|
38018
38222
|
if (!_warmPromise) {
|
|
38019
38223
|
_warmPromise = refreshCatalog(8000).then(() => {
|
|
@@ -38038,6 +38242,7 @@ async function ensureCatalogReady(timeoutMs = 5000) {
|
|
|
38038
38242
|
var DEFAULT_CATALOG_URL = "https://us-central1-claudish-6da10.cloudfunctions.net/queryModels?status=active&catalog=slim&limit=1000", _memCache = null, _catalogEntriesForTest, _warmPromise = null, CATALOG_REVISION_HEADER = "x-catalog-revision", MAX_CATALOG_PAGES = 40, CATALOG_PAGE_LIMIT = 1000;
|
|
38039
38243
|
var init_catalog_client = __esm(() => {
|
|
38040
38244
|
init_all_models_cache();
|
|
38245
|
+
init_catalog_compatibility();
|
|
38041
38246
|
});
|
|
38042
38247
|
|
|
38043
38248
|
// src/config-schema.ts
|
|
@@ -39306,7 +39511,16 @@ function globMatch(pattern, value) {
|
|
|
39306
39511
|
async function hasCredentialsForProvider(provider) {
|
|
39307
39512
|
return credentials.isAvailable(provider);
|
|
39308
39513
|
}
|
|
39514
|
+
function warnOnceIfCatalogIncompatible() {
|
|
39515
|
+
if (_warnedCatalogIncompatible)
|
|
39516
|
+
return;
|
|
39517
|
+
if (!readCatalogIncompatibility())
|
|
39518
|
+
return;
|
|
39519
|
+
_warnedCatalogIncompatible = true;
|
|
39520
|
+
logStderr("Model catalog is unavailable \u2014 this build cannot read the catalog server's current " + "contract. Explicit provider@model routing still works; bare model names do not. " + "Run `claudish update`.");
|
|
39521
|
+
}
|
|
39309
39522
|
async function routeExplicit(modelSpec, model, provider, cachePath) {
|
|
39523
|
+
warnOnceIfCatalogIncompatible();
|
|
39310
39524
|
if (!await hasCredentialsForProvider(provider)) {
|
|
39311
39525
|
return {
|
|
39312
39526
|
kind: "no-route",
|
|
@@ -39331,6 +39545,10 @@ async function routeExplicit(modelSpec, model, provider, cachePath) {
|
|
|
39331
39545
|
return { kind: "ok", primary: built, fallbacks: [] };
|
|
39332
39546
|
}
|
|
39333
39547
|
async function routeBare(model, nativeProvider, rules, defaultProvider, cachePath) {
|
|
39548
|
+
const incompatible = readCatalogIncompatibility();
|
|
39549
|
+
if (incompatible) {
|
|
39550
|
+
throw new CatalogIncompatibleError(catalogIncompatibilityMessage(incompatible));
|
|
39551
|
+
}
|
|
39334
39552
|
const matched = matchRoutingRule(model, rules) ?? [];
|
|
39335
39553
|
const entries = [...matched];
|
|
39336
39554
|
if (defaultProvider && defaultProvider.length > 0) {
|
|
@@ -39412,6 +39630,7 @@ async function route(modelSpec, rulesOverride, defaultProviderOverride, cachePat
|
|
|
39412
39630
|
const defaultProvider = defaultProviderOverride !== undefined ? defaultProviderOverride : rulesOverride !== undefined ? undefined : loadConfig().defaultProvider;
|
|
39413
39631
|
return routeBare(normalizeGlmSlug(parsed.model), parsed.provider, rules, defaultProvider, cachePath);
|
|
39414
39632
|
}
|
|
39633
|
+
var _warnedCatalogIncompatible = false;
|
|
39415
39634
|
var init_routing_rules = __esm(() => {
|
|
39416
39635
|
init_model_catalog();
|
|
39417
39636
|
init_authority();
|
|
@@ -39420,6 +39639,7 @@ var init_routing_rules = __esm(() => {
|
|
|
39420
39639
|
init_profile_config();
|
|
39421
39640
|
init_auto_route();
|
|
39422
39641
|
init_catalog_client();
|
|
39642
|
+
init_catalog_compatibility();
|
|
39423
39643
|
init_default_routing_rules();
|
|
39424
39644
|
init_model_availability();
|
|
39425
39645
|
init_model_parser();
|
|
@@ -40524,8 +40744,8 @@ __export(exports_session_discovery, {
|
|
|
40524
40744
|
});
|
|
40525
40745
|
import { execFile, execFileSync as execFileSync2 } from "child_process";
|
|
40526
40746
|
import { closeSync as closeSync6, openSync as openSync6, readSync as readSync2, readdirSync as readdirSync4, realpathSync, statSync as statSync5 } from "fs";
|
|
40527
|
-
import { homedir as
|
|
40528
|
-
import { basename, join as
|
|
40747
|
+
import { homedir as homedir28 } from "os";
|
|
40748
|
+
import { basename, join as join28 } from "path";
|
|
40529
40749
|
function slugForPath(absPath) {
|
|
40530
40750
|
return absPath.replace(/[/.]/g, "-");
|
|
40531
40751
|
}
|
|
@@ -40534,7 +40754,7 @@ function transcriptPathFor(cwd, sessionUuid) {
|
|
|
40534
40754
|
try {
|
|
40535
40755
|
real = realpathSync(cwd);
|
|
40536
40756
|
} catch {}
|
|
40537
|
-
return
|
|
40757
|
+
return join28(PROJECTS_DIR, slugForPath(real), `${sessionUuid}.jsonl`);
|
|
40538
40758
|
}
|
|
40539
40759
|
function isAgentSession(row) {
|
|
40540
40760
|
return row.entrypoint !== undefined && row.entrypoint !== "cli";
|
|
@@ -40581,7 +40801,7 @@ function projectDirs() {
|
|
|
40581
40801
|
}
|
|
40582
40802
|
}
|
|
40583
40803
|
function sessionsIn(dirName) {
|
|
40584
|
-
const dir =
|
|
40804
|
+
const dir = join28(PROJECTS_DIR, dirName);
|
|
40585
40805
|
let names;
|
|
40586
40806
|
try {
|
|
40587
40807
|
names = readdirSync4(dir).filter((n) => n.endsWith(".jsonl"));
|
|
@@ -40590,7 +40810,7 @@ function sessionsIn(dirName) {
|
|
|
40590
40810
|
}
|
|
40591
40811
|
const rows = [];
|
|
40592
40812
|
for (const n of names) {
|
|
40593
|
-
const file =
|
|
40813
|
+
const file = join28(dir, n);
|
|
40594
40814
|
try {
|
|
40595
40815
|
const st = statSync5(file);
|
|
40596
40816
|
if (st.size === 0)
|
|
@@ -40952,7 +41172,7 @@ function findLatestSessionId(cwd = process.cwd(), sinceMs = 0) {
|
|
|
40952
41172
|
}
|
|
40953
41173
|
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;
|
|
40954
41174
|
var init_session_discovery = __esm(() => {
|
|
40955
|
-
PROJECTS_DIR =
|
|
41175
|
+
PROJECTS_DIR = join28(homedir28(), ".claude", "projects");
|
|
40956
41176
|
HEAD_BYTES = 64 * 1024;
|
|
40957
41177
|
TAIL_BYTES = 128 * 1024;
|
|
40958
41178
|
HARNESS_ENVELOPES = [
|
|
@@ -40987,19 +41207,19 @@ function newStdioDecoder() {
|
|
|
40987
41207
|
var init_stdio_decode = () => {};
|
|
40988
41208
|
|
|
40989
41209
|
// src/team-stats.ts
|
|
40990
|
-
import { existsSync as
|
|
40991
|
-
import { join as
|
|
41210
|
+
import { existsSync as existsSync20, readFileSync as readFileSync19, writeFileSync as writeFileSync11 } from "fs";
|
|
41211
|
+
import { join as join29 } from "path";
|
|
40992
41212
|
function statsDir(sessionPath) {
|
|
40993
|
-
return
|
|
41213
|
+
return join29(sessionPath, "stats");
|
|
40994
41214
|
}
|
|
40995
41215
|
function tokenFileFor(sessionPath, anonId) {
|
|
40996
|
-
return
|
|
41216
|
+
return join29(statsDir(sessionPath), `${anonId}.json`);
|
|
40997
41217
|
}
|
|
40998
41218
|
function readTokenStatsAt(path) {
|
|
40999
|
-
if (!
|
|
41219
|
+
if (!existsSync20(path))
|
|
41000
41220
|
return null;
|
|
41001
41221
|
try {
|
|
41002
|
-
return JSON.parse(
|
|
41222
|
+
return JSON.parse(readFileSync19(path, "utf-8"));
|
|
41003
41223
|
} catch {
|
|
41004
41224
|
return null;
|
|
41005
41225
|
}
|
|
@@ -41150,7 +41370,7 @@ ${segs.join(" \xB7 ")}`;
|
|
|
41150
41370
|
}
|
|
41151
41371
|
function writeStatusFile(sessionPath, manifest, status, opts) {
|
|
41152
41372
|
try {
|
|
41153
|
-
|
|
41373
|
+
writeFileSync11(join29(sessionPath, "status.txt"), `${renderTeamStats(sessionPath, manifest, status, opts)}
|
|
41154
41374
|
`, "utf-8");
|
|
41155
41375
|
} catch {}
|
|
41156
41376
|
}
|
|
@@ -41161,13 +41381,13 @@ var init_team_stats = () => {};
|
|
|
41161
41381
|
import { spawn as spawn2 } from "child_process";
|
|
41162
41382
|
import {
|
|
41163
41383
|
createWriteStream,
|
|
41164
|
-
existsSync as
|
|
41165
|
-
mkdirSync as
|
|
41166
|
-
readFileSync as
|
|
41384
|
+
existsSync as existsSync21,
|
|
41385
|
+
mkdirSync as mkdirSync12,
|
|
41386
|
+
readFileSync as readFileSync20,
|
|
41167
41387
|
readdirSync as readdirSync5,
|
|
41168
|
-
writeFileSync as
|
|
41388
|
+
writeFileSync as writeFileSync12
|
|
41169
41389
|
} from "fs";
|
|
41170
|
-
import { basename as basename2, join as
|
|
41390
|
+
import { basename as basename2, join as join30, resolve as resolve3 } from "path";
|
|
41171
41391
|
function resolveCaptureMode(explicit, env = process.env) {
|
|
41172
41392
|
if (explicit)
|
|
41173
41393
|
return explicit;
|
|
@@ -41315,7 +41535,7 @@ function persistErrorLog(errorLogPath, header, stderr, stdoutTail) {
|
|
|
41315
41535
|
parts.push("--- stderr ---", stderr.trim() ? redactSecrets(stderr) : "(empty)", "");
|
|
41316
41536
|
parts.push("--- stdout (tail) ---", stdoutTail.trim() ? redactSecrets(stdoutTail) : "(empty)", "");
|
|
41317
41537
|
try {
|
|
41318
|
-
|
|
41538
|
+
writeFileSync12(errorLogPath, parts.join(`
|
|
41319
41539
|
`), "utf-8");
|
|
41320
41540
|
} catch {}
|
|
41321
41541
|
}
|
|
@@ -41333,10 +41553,10 @@ function readTeamInputFile(inputPath) {
|
|
|
41333
41553
|
if (!resolved.startsWith(`${cwd}/`) && resolved !== cwd) {
|
|
41334
41554
|
throw new Error(`Input file must be within current directory: ${inputPath}`);
|
|
41335
41555
|
}
|
|
41336
|
-
if (!
|
|
41556
|
+
if (!existsSync21(resolved)) {
|
|
41337
41557
|
throw new Error(`Input file not found: ${resolved}`);
|
|
41338
41558
|
}
|
|
41339
|
-
const text =
|
|
41559
|
+
const text = readFileSync20(resolved, "utf-8");
|
|
41340
41560
|
if (text.trim().length === 0) {
|
|
41341
41561
|
throw new Error(`Input file is empty: ${resolved}`);
|
|
41342
41562
|
}
|
|
@@ -41346,14 +41566,14 @@ function setupSession(sessionPath, models, input) {
|
|
|
41346
41566
|
if (models.length === 0) {
|
|
41347
41567
|
throw new Error("At least one model is required");
|
|
41348
41568
|
}
|
|
41349
|
-
if (
|
|
41569
|
+
if (existsSync21(join30(sessionPath, "manifest.json"))) {
|
|
41350
41570
|
throw new Error(`Session already exists at ${sessionPath}. Use a new directory path or delete the existing session first.`);
|
|
41351
41571
|
}
|
|
41352
|
-
|
|
41353
|
-
|
|
41572
|
+
mkdirSync12(join30(sessionPath, "work"), { recursive: true });
|
|
41573
|
+
mkdirSync12(join30(sessionPath, "errors"), { recursive: true });
|
|
41354
41574
|
if (input !== undefined) {
|
|
41355
|
-
|
|
41356
|
-
} else if (!
|
|
41575
|
+
writeFileSync12(join30(sessionPath, "input.md"), input, "utf-8");
|
|
41576
|
+
} else if (!existsSync21(join30(sessionPath, "input.md"))) {
|
|
41357
41577
|
throw new Error(`No input.md found at ${sessionPath} and no input provided`);
|
|
41358
41578
|
}
|
|
41359
41579
|
const ids = models.map((_, i) => String(i + 1).padStart(2, "0"));
|
|
@@ -41370,9 +41590,9 @@ function setupSession(sessionPath, models, input) {
|
|
|
41370
41590
|
model: models[i],
|
|
41371
41591
|
assignedAt: now
|
|
41372
41592
|
};
|
|
41373
|
-
|
|
41593
|
+
mkdirSync12(join30(sessionPath, "work", anonId), { recursive: true });
|
|
41374
41594
|
}
|
|
41375
|
-
|
|
41595
|
+
writeFileSync12(join30(sessionPath, "manifest.json"), JSON.stringify(manifest, null, 2), "utf-8");
|
|
41376
41596
|
const status = {
|
|
41377
41597
|
startedAt: now,
|
|
41378
41598
|
models: Object.fromEntries(Object.keys(manifest.models).map((id) => [
|
|
@@ -41386,7 +41606,7 @@ function setupSession(sessionPath, models, input) {
|
|
|
41386
41606
|
}
|
|
41387
41607
|
]))
|
|
41388
41608
|
};
|
|
41389
|
-
|
|
41609
|
+
writeFileSync12(join30(sessionPath, "status.json"), JSON.stringify(status, null, 2), "utf-8");
|
|
41390
41610
|
return manifest;
|
|
41391
41611
|
}
|
|
41392
41612
|
function assertValidRequirePattern(pattern) {
|
|
@@ -41403,22 +41623,22 @@ function readFullOutputIfNeeded(opts) {
|
|
|
41403
41623
|
if (crashed || !requirePattern || outputSize <= STDOUT_TAIL_LIMIT)
|
|
41404
41624
|
return;
|
|
41405
41625
|
try {
|
|
41406
|
-
return
|
|
41626
|
+
return readFileSync20(outputPath, "utf-8");
|
|
41407
41627
|
} catch {
|
|
41408
41628
|
return;
|
|
41409
41629
|
}
|
|
41410
41630
|
}
|
|
41411
41631
|
async function startModels(sessionPath, opts = {}) {
|
|
41412
41632
|
assertValidRequirePattern(opts.requirePattern);
|
|
41413
|
-
const manifest = JSON.parse(
|
|
41414
|
-
const statusPath =
|
|
41415
|
-
const inputPath =
|
|
41416
|
-
const inputContent =
|
|
41633
|
+
const manifest = JSON.parse(readFileSync20(join30(sessionPath, "manifest.json"), "utf-8"));
|
|
41634
|
+
const statusPath = join30(sessionPath, "status.json");
|
|
41635
|
+
const inputPath = join30(sessionPath, "input.md");
|
|
41636
|
+
const inputContent = readFileSync20(inputPath, "utf-8");
|
|
41417
41637
|
const spawnPlan = await (opts.spawnPlanner ?? prehydrateCredentialsForSpawn)(Object.values(manifest.models).map((m) => m.model));
|
|
41418
|
-
const statusCache = JSON.parse(
|
|
41638
|
+
const statusCache = JSON.parse(readFileSync20(statusPath, "utf-8"));
|
|
41419
41639
|
function updateModelStatus(id, update) {
|
|
41420
41640
|
statusCache.models[id] = { ...statusCache.models[id], ...update };
|
|
41421
|
-
|
|
41641
|
+
writeFileSync12(statusPath, JSON.stringify(statusCache, null, 2), "utf-8");
|
|
41422
41642
|
}
|
|
41423
41643
|
const minOutputBytes = opts.minOutputBytes ?? DEFAULT_MIN_OUTPUT_BYTES;
|
|
41424
41644
|
const requirePattern = opts.requirePattern;
|
|
@@ -41451,7 +41671,7 @@ async function startModels(sessionPath, opts = {}) {
|
|
|
41451
41671
|
persistErrorLog(rt.errorLogPath, `RECOVERED: ${note}`, stderr, stdoutTail);
|
|
41452
41672
|
opts.onStatusChange?.(id, statusCache.models[id]);
|
|
41453
41673
|
}
|
|
41454
|
-
|
|
41674
|
+
mkdirSync12(statsDir(sessionPath), { recursive: true });
|
|
41455
41675
|
const processes = new Map;
|
|
41456
41676
|
const runtimes = new Map;
|
|
41457
41677
|
const cancelledSlots = new Set;
|
|
@@ -41464,9 +41684,9 @@ async function startModels(sessionPath, opts = {}) {
|
|
|
41464
41684
|
process.on("SIGINT", sigintHandler);
|
|
41465
41685
|
const completionPromises = [];
|
|
41466
41686
|
for (const [anonId, entry] of Object.entries(manifest.models)) {
|
|
41467
|
-
const outputPath =
|
|
41468
|
-
const errorLogPath =
|
|
41469
|
-
const upstreamErrorLogPath =
|
|
41687
|
+
const outputPath = join30(sessionPath, `response-${anonId}.md`);
|
|
41688
|
+
const errorLogPath = join30(sessionPath, "errors", `${anonId}.log`);
|
|
41689
|
+
const upstreamErrorLogPath = join30(sessionPath, "errors", `${anonId}-upstream.jsonl`);
|
|
41470
41690
|
const spawnModel = spawnPlan.pinned.get(entry.model) ?? entry.model;
|
|
41471
41691
|
const args = [
|
|
41472
41692
|
"--model",
|
|
@@ -41620,7 +41840,7 @@ async function startModels(sessionPath, opts = {}) {
|
|
|
41620
41840
|
stderrSnippet: stderr ? redactSecrets(stderr).slice(-2000) : undefined,
|
|
41621
41841
|
stdoutSnippet: stdoutTail ? snippetHeadAndTail(redactSecrets(stdoutTail)) : undefined,
|
|
41622
41842
|
errorLogPath,
|
|
41623
|
-
upstreamErrorLogPath:
|
|
41843
|
+
upstreamErrorLogPath: existsSync21(upstreamErrorLogPath) ? upstreamErrorLogPath : undefined,
|
|
41624
41844
|
workDir: sessionPath
|
|
41625
41845
|
}
|
|
41626
41846
|
});
|
|
@@ -41641,7 +41861,7 @@ async function startModels(sessionPath, opts = {}) {
|
|
|
41641
41861
|
proc.on("exit", (code) => {
|
|
41642
41862
|
const timedOut = statusCache.models[anonId]?.state === "TIMEOUT";
|
|
41643
41863
|
if (!timedOut && meaningfulStderr(stderr)) {
|
|
41644
|
-
|
|
41864
|
+
writeFileSync12(errorLogPath, redactSecrets(stderr), "utf-8");
|
|
41645
41865
|
}
|
|
41646
41866
|
exitCode = code;
|
|
41647
41867
|
if (outputStream.destroyed) {
|
|
@@ -41723,23 +41943,23 @@ async function judgeResponses(sessionPath, opts = {}) {
|
|
|
41723
41943
|
const responses = {};
|
|
41724
41944
|
for (const file of responseFiles) {
|
|
41725
41945
|
const id = file.replace(/^response-/, "").replace(/\.md$/, "");
|
|
41726
|
-
responses[id] =
|
|
41946
|
+
responses[id] = readFileSync20(join30(sessionPath, file), "utf-8");
|
|
41727
41947
|
}
|
|
41728
|
-
const input =
|
|
41948
|
+
const input = readFileSync20(join30(sessionPath, "input.md"), "utf-8");
|
|
41729
41949
|
const judgePrompt = buildJudgePrompt(input, responses);
|
|
41730
|
-
|
|
41950
|
+
writeFileSync12(join30(sessionPath, "judge-prompt.md"), judgePrompt, "utf-8");
|
|
41731
41951
|
const judgeModels = opts.judges ?? getDefaultJudgeModels(sessionPath);
|
|
41732
|
-
const judgePath =
|
|
41733
|
-
|
|
41952
|
+
const judgePath = join30(sessionPath, "judging");
|
|
41953
|
+
mkdirSync12(judgePath, { recursive: true });
|
|
41734
41954
|
setupSession(judgePath, judgeModels, judgePrompt);
|
|
41735
41955
|
await runModels(judgePath, { claudeFlags: opts.claudeFlags });
|
|
41736
41956
|
const votes = parseJudgeVotes(judgePath, Object.keys(responses));
|
|
41737
41957
|
const verdict = aggregateVerdict(votes, Object.keys(responses));
|
|
41738
|
-
|
|
41958
|
+
writeFileSync12(join30(sessionPath, "verdict.md"), formatVerdict(verdict, sessionPath), "utf-8");
|
|
41739
41959
|
return verdict;
|
|
41740
41960
|
}
|
|
41741
41961
|
function getStatus(sessionPath) {
|
|
41742
|
-
return JSON.parse(
|
|
41962
|
+
return JSON.parse(readFileSync20(join30(sessionPath, "status.json"), "utf-8"));
|
|
41743
41963
|
}
|
|
41744
41964
|
function fisherYatesShuffle(arr) {
|
|
41745
41965
|
for (let i = arr.length - 1;i > 0; i--) {
|
|
@@ -41749,7 +41969,7 @@ function fisherYatesShuffle(arr) {
|
|
|
41749
41969
|
return arr;
|
|
41750
41970
|
}
|
|
41751
41971
|
function getDefaultJudgeModels(sessionPath) {
|
|
41752
|
-
const manifest = JSON.parse(
|
|
41972
|
+
const manifest = JSON.parse(readFileSync20(join30(sessionPath, "manifest.json"), "utf-8"));
|
|
41753
41973
|
return Object.values(manifest.models).map((e) => e.model);
|
|
41754
41974
|
}
|
|
41755
41975
|
function buildJudgePrompt(input, responses) {
|
|
@@ -41812,7 +42032,7 @@ function parseJudgeVotes(judgePath, responseIds) {
|
|
|
41812
42032
|
const judgeId = file.replace(/^response-/, "").replace(/\.md$/, "");
|
|
41813
42033
|
let content;
|
|
41814
42034
|
try {
|
|
41815
|
-
content =
|
|
42035
|
+
content = readFileSync20(join30(judgePath, file), "utf-8");
|
|
41816
42036
|
} catch {
|
|
41817
42037
|
continue;
|
|
41818
42038
|
}
|
|
@@ -41864,7 +42084,7 @@ function aggregateVerdict(votes, responseIds) {
|
|
|
41864
42084
|
function formatVerdict(verdict, sessionPath) {
|
|
41865
42085
|
let manifest = null;
|
|
41866
42086
|
try {
|
|
41867
|
-
manifest = JSON.parse(
|
|
42087
|
+
manifest = JSON.parse(readFileSync20(join30(sessionPath, "manifest.json"), "utf-8"));
|
|
41868
42088
|
} catch {}
|
|
41869
42089
|
let output = `# Team Verdict
|
|
41870
42090
|
|
|
@@ -41918,15 +42138,15 @@ import {
|
|
|
41918
42138
|
appendFileSync as appendFileSync6,
|
|
41919
42139
|
closeSync as closeSync7,
|
|
41920
42140
|
createWriteStream as createWriteStream2,
|
|
41921
|
-
mkdirSync as
|
|
42141
|
+
mkdirSync as mkdirSync13,
|
|
41922
42142
|
openSync as openSync7,
|
|
41923
|
-
readFileSync as
|
|
42143
|
+
readFileSync as readFileSync21,
|
|
41924
42144
|
readSync as readSync3,
|
|
41925
42145
|
statSync as statSync6,
|
|
41926
|
-
writeFileSync as
|
|
42146
|
+
writeFileSync as writeFileSync13
|
|
41927
42147
|
} from "fs";
|
|
41928
|
-
import { homedir as
|
|
41929
|
-
import { join as
|
|
42148
|
+
import { homedir as homedir29 } from "os";
|
|
42149
|
+
import { join as join31, resolve as resolve4, sep } from "path";
|
|
41930
42150
|
import { StringDecoder as StringDecoder2 } from "string_decoder";
|
|
41931
42151
|
function buildChannelSpawnArgs(opts) {
|
|
41932
42152
|
return [
|
|
@@ -42001,7 +42221,7 @@ function readJsonObject(path, maxBytes) {
|
|
|
42001
42221
|
try {
|
|
42002
42222
|
if (fileSize(path) > maxBytes)
|
|
42003
42223
|
return null;
|
|
42004
|
-
const parsed = JSON.parse(
|
|
42224
|
+
const parsed = JSON.parse(readFileSync21(path, "utf-8"));
|
|
42005
42225
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
42006
42226
|
return null;
|
|
42007
42227
|
return parsed;
|
|
@@ -42017,7 +42237,7 @@ function dropLeadingFragment(tail) {
|
|
|
42017
42237
|
return firstBreak === -1 ? tail.text : tail.text.slice(firstBreak + 1);
|
|
42018
42238
|
}
|
|
42019
42239
|
function diskAccounting(sessionDir) {
|
|
42020
|
-
const stats = readTokenStatsAt(
|
|
42240
|
+
const stats = readTokenStatsAt(join31(sessionDir, "tokens.json"));
|
|
42021
42241
|
return {
|
|
42022
42242
|
tokensUsed: (stats?.total_tokens ?? 0) || (stats?.input_tokens ?? 0) + (stats?.output_tokens ?? 0),
|
|
42023
42243
|
costUsd: stats?.total_cost ?? 0,
|
|
@@ -42057,7 +42277,7 @@ class SessionManager {
|
|
|
42057
42277
|
this.maxSessions = options?.maxSessions ?? DEFAULT_MAX_SESSIONS;
|
|
42058
42278
|
this.scrollbackCapacity = options?.scrollbackCapacity ?? DEFAULT_SCROLLBACK;
|
|
42059
42279
|
this.terminalRetentionMs = options?.terminalRetentionMs ?? TERMINAL_RETENTION_MS;
|
|
42060
|
-
this.sessionsDir = options?.sessionsDir ?? process.env.CLAUDISH_SESSIONS_DIR ??
|
|
42280
|
+
this.sessionsDir = options?.sessionsDir ?? process.env.CLAUDISH_SESSIONS_DIR ?? join31(homedir29(), ".claudish", "sessions");
|
|
42061
42281
|
this.stallSeconds = options?.stallSeconds;
|
|
42062
42282
|
this.onStateChange = options?.onStateChange;
|
|
42063
42283
|
}
|
|
@@ -42073,19 +42293,19 @@ class SessionManager {
|
|
|
42073
42293
|
const claudeSessionId = randomUUID4();
|
|
42074
42294
|
const timeout = Math.min(opts.timeoutSeconds ?? DEFAULT_TIMEOUT, MAX_TIMEOUT);
|
|
42075
42295
|
const startedAt = new Date().toISOString();
|
|
42076
|
-
const sessionDir = opts.sessionDir ??
|
|
42077
|
-
|
|
42296
|
+
const sessionDir = opts.sessionDir ?? join31(this.sessionsDir, sessionId);
|
|
42297
|
+
mkdirSync13(sessionDir, { recursive: true });
|
|
42078
42298
|
if (opts.prompt) {
|
|
42079
|
-
|
|
42299
|
+
writeFileSync13(join31(sessionDir, "prompt.md"), opts.prompt, "utf-8");
|
|
42080
42300
|
}
|
|
42081
42301
|
const args = buildChannelSpawnArgs({
|
|
42082
42302
|
model: opts.spawnModel ?? opts.model,
|
|
42083
42303
|
claudeSessionId,
|
|
42084
42304
|
claudishFlags: opts.claudishFlags
|
|
42085
42305
|
});
|
|
42086
|
-
const tokenFile = opts.tokenFile ??
|
|
42087
|
-
const eventLogPath =
|
|
42088
|
-
const upstreamErrorLogPath =
|
|
42306
|
+
const tokenFile = opts.tokenFile ?? join31(sessionDir, "tokens.json");
|
|
42307
|
+
const eventLogPath = join31(sessionDir, "events.jsonl");
|
|
42308
|
+
const upstreamErrorLogPath = join31(sessionDir, "upstream-errors.jsonl");
|
|
42089
42309
|
const cwd = opts.cwd ?? process.cwd();
|
|
42090
42310
|
const spawnTarget = resolveClaudishSpawn();
|
|
42091
42311
|
const proc = spawn3(spawnTarget.command, [...spawnTarget.prefixArgs, ...args], {
|
|
@@ -42100,7 +42320,7 @@ class SessionManager {
|
|
|
42100
42320
|
}
|
|
42101
42321
|
});
|
|
42102
42322
|
const scrollback = new ScrollbackBuffer(this.scrollbackCapacity);
|
|
42103
|
-
const outputLogStream = createWriteStream2(
|
|
42323
|
+
const outputLogStream = createWriteStream2(join31(sessionDir, "output.log"));
|
|
42104
42324
|
const entry = {
|
|
42105
42325
|
info: {
|
|
42106
42326
|
sessionId,
|
|
@@ -42392,7 +42612,7 @@ class SessionManager {
|
|
|
42392
42612
|
return null;
|
|
42393
42613
|
const root = resolve4(this.sessionsDir);
|
|
42394
42614
|
const dir = resolve4(root, sessionId);
|
|
42395
|
-
if (dir !==
|
|
42615
|
+
if (dir !== join31(root, sessionId))
|
|
42396
42616
|
return null;
|
|
42397
42617
|
if (!dir.startsWith(root + sep))
|
|
42398
42618
|
return null;
|
|
@@ -42411,7 +42631,7 @@ class SessionManager {
|
|
|
42411
42631
|
} catch {
|
|
42412
42632
|
return null;
|
|
42413
42633
|
}
|
|
42414
|
-
const meta = readJsonObject(
|
|
42634
|
+
const meta = readJsonObject(join31(sessionDir, "meta.json"), META_READ_LIMIT);
|
|
42415
42635
|
const partial = meta === null;
|
|
42416
42636
|
const measured = diskAccounting(sessionDir);
|
|
42417
42637
|
const startedAt = metaString(meta?.startedAt) ?? new Date(dirMtimeMs).toISOString();
|
|
@@ -42441,7 +42661,7 @@ class SessionManager {
|
|
|
42441
42661
|
};
|
|
42442
42662
|
}
|
|
42443
42663
|
diskOutput(record, tailLines) {
|
|
42444
|
-
const tail = readTailText(
|
|
42664
|
+
const tail = readTailText(join31(record.sessionDir, "output.log"), OUTPUT_TAIL_BYTES);
|
|
42445
42665
|
const buffer = new ScrollbackBuffer(this.scrollbackCapacity);
|
|
42446
42666
|
if (tail?.text)
|
|
42447
42667
|
buffer.append(dropLeadingFragment(tail));
|
|
@@ -42460,9 +42680,9 @@ class SessionManager {
|
|
|
42460
42680
|
}
|
|
42461
42681
|
diskDiagnostics(record, limit) {
|
|
42462
42682
|
const { sessionDir, info } = record;
|
|
42463
|
-
const eventLogPath =
|
|
42464
|
-
const upstreamErrorLogPath =
|
|
42465
|
-
const outputLogPath =
|
|
42683
|
+
const eventLogPath = join31(sessionDir, "events.jsonl");
|
|
42684
|
+
const upstreamErrorLogPath = join31(sessionDir, "upstream-errors.jsonl");
|
|
42685
|
+
const outputLogPath = join31(sessionDir, "output.log");
|
|
42466
42686
|
const events = readTailLines(eventLogPath, EVENT_TAIL_BYTES);
|
|
42467
42687
|
const outputTail = readTailText(outputLogPath, OUTPUT_TAIL_BYTES);
|
|
42468
42688
|
return {
|
|
@@ -42504,7 +42724,7 @@ class SessionManager {
|
|
|
42504
42724
|
};
|
|
42505
42725
|
}
|
|
42506
42726
|
diskStderrForDiagnostics(record) {
|
|
42507
|
-
const tail = readTailText(
|
|
42727
|
+
const tail = readTailText(join31(record.sessionDir, "stderr.log"), STDERR_READ_BYTES);
|
|
42508
42728
|
const raw = tail?.text ?? "";
|
|
42509
42729
|
const filtered = record.info.status === "completed";
|
|
42510
42730
|
const source = filtered ? meaningfulStderr(raw) : raw;
|
|
@@ -42680,11 +42900,11 @@ ${STDERR_TRUNCATION_MARKER} ${STDERR_SIDE_LIMIT} bytes per end \u2026
|
|
|
42680
42900
|
entry.outputLogStream?.end();
|
|
42681
42901
|
entry.outputLogStream = null;
|
|
42682
42902
|
if (entry.stderr) {
|
|
42683
|
-
|
|
42903
|
+
writeFileSync13(join31(entry.sessionDir, "stderr.log"), redactSecrets(entry.stderr), "utf-8");
|
|
42684
42904
|
}
|
|
42685
42905
|
this.refreshAccounting(entry);
|
|
42686
42906
|
entry.info.claudeSessionId = entry.reducer.claudeSessionId ?? entry.info.claudeSessionId;
|
|
42687
|
-
|
|
42907
|
+
writeFileSync13(join31(entry.sessionDir, "meta.json"), JSON.stringify(entry.info, null, 2), "utf-8");
|
|
42688
42908
|
}
|
|
42689
42909
|
scheduleEviction(entry) {
|
|
42690
42910
|
if (entry.evictHandle)
|
|
@@ -42744,7 +42964,7 @@ ${STDERR_TRUNCATION_MARKER} ${STDERR_SIDE_LIMIT} bytes per end \u2026
|
|
|
42744
42964
|
return { state: "completed", content: "" };
|
|
42745
42965
|
}
|
|
42746
42966
|
refreshAccounting(entry) {
|
|
42747
|
-
const stats = readTokenStatsAt(
|
|
42967
|
+
const stats = readTokenStatsAt(join31(entry.sessionDir, "tokens.json"));
|
|
42748
42968
|
const fileTokens = (stats?.total_tokens ?? 0) || (stats?.input_tokens ?? 0) + (stats?.output_tokens ?? 0);
|
|
42749
42969
|
entry.info.tokensUsed = fileTokens || entry.reducer.tokens;
|
|
42750
42970
|
entry.info.costUsd = stats?.total_cost ?? 0;
|
|
@@ -42942,9 +43162,9 @@ var init_cache_ttl = __esm(() => {
|
|
|
42942
43162
|
});
|
|
42943
43163
|
|
|
42944
43164
|
// src/model-loader.ts
|
|
42945
|
-
import { existsSync as
|
|
42946
|
-
import { homedir as
|
|
42947
|
-
import { join as
|
|
43165
|
+
import { existsSync as existsSync22, mkdirSync as mkdirSync14, readFileSync as readFileSync22, writeFileSync as writeFileSync14 } from "fs";
|
|
43166
|
+
import { homedir as homedir30 } from "os";
|
|
43167
|
+
import { join as join32 } from "path";
|
|
42948
43168
|
function groupRecommendedModels(entries) {
|
|
42949
43169
|
const byId = new Map;
|
|
42950
43170
|
const categoryOrder = new Map;
|
|
@@ -43072,9 +43292,9 @@ async function getRecommendedModels(opts = {}) {
|
|
|
43072
43292
|
if (!forceRefresh && _cachedRecommendedModels) {
|
|
43073
43293
|
return _cachedRecommendedModels;
|
|
43074
43294
|
}
|
|
43075
|
-
if (!forceRefresh &&
|
|
43295
|
+
if (!forceRefresh && existsSync22(RECOMMENDED_MODELS_CACHE_PATH)) {
|
|
43076
43296
|
try {
|
|
43077
|
-
const cacheData = JSON.parse(
|
|
43297
|
+
const cacheData = JSON.parse(readFileSync22(RECOMMENDED_MODELS_CACHE_PATH, "utf-8"));
|
|
43078
43298
|
if (cacheData.models && cacheData.models.length > 0 && isFreshEnough(cacheData)) {
|
|
43079
43299
|
_cachedRecommendedModels = cacheData;
|
|
43080
43300
|
return cacheData;
|
|
@@ -43090,9 +43310,9 @@ async function getRecommendedModels(opts = {}) {
|
|
|
43090
43310
|
if (data.models && data.models.length > 0) {
|
|
43091
43311
|
_cachedRecommendedModels = data;
|
|
43092
43312
|
try {
|
|
43093
|
-
const cacheDir =
|
|
43094
|
-
|
|
43095
|
-
|
|
43313
|
+
const cacheDir = join32(homedir30(), ".claudish");
|
|
43314
|
+
mkdirSync14(cacheDir, { recursive: true });
|
|
43315
|
+
writeFileSync14(RECOMMENDED_MODELS_CACHE_PATH, JSON.stringify(data), "utf-8");
|
|
43096
43316
|
} catch {}
|
|
43097
43317
|
return data;
|
|
43098
43318
|
}
|
|
@@ -43103,9 +43323,9 @@ async function getRecommendedModels(opts = {}) {
|
|
|
43103
43323
|
function getRecommendedModelsSync() {
|
|
43104
43324
|
if (_cachedRecommendedModels)
|
|
43105
43325
|
return _cachedRecommendedModels;
|
|
43106
|
-
if (
|
|
43326
|
+
if (existsSync22(RECOMMENDED_MODELS_CACHE_PATH)) {
|
|
43107
43327
|
try {
|
|
43108
|
-
const cacheData = JSON.parse(
|
|
43328
|
+
const cacheData = JSON.parse(readFileSync22(RECOMMENDED_MODELS_CACHE_PATH, "utf-8"));
|
|
43109
43329
|
if (cacheData.models && cacheData.models.length > 0 && isFreshEnough(cacheData)) {
|
|
43110
43330
|
_cachedRecommendedModels = cacheData;
|
|
43111
43331
|
return cacheData;
|
|
@@ -43229,7 +43449,7 @@ var _cachedModelInfo = null, _cachedModelIds = null, _cachedRecommendedModels =
|
|
|
43229
43449
|
var init_model_loader = __esm(() => {
|
|
43230
43450
|
init_cache_ttl();
|
|
43231
43451
|
FIREBASE_RECOMMENDED_URL = `${FIREBASE_BASE_URL}?catalog=recommended`;
|
|
43232
|
-
RECOMMENDED_MODELS_CACHE_PATH =
|
|
43452
|
+
RECOMMENDED_MODELS_CACHE_PATH = join32(homedir30(), ".claudish", "recommended-models-cache.json");
|
|
43233
43453
|
FIREBASE_SLUG_TO_PROVIDER_NAME = {
|
|
43234
43454
|
openai: "openai",
|
|
43235
43455
|
google: "google",
|
|
@@ -48239,9 +48459,9 @@ var init_poe = __esm(() => {
|
|
|
48239
48459
|
});
|
|
48240
48460
|
|
|
48241
48461
|
// src/services/pricing-cache.ts
|
|
48242
|
-
import { existsSync as
|
|
48243
|
-
import { homedir as
|
|
48244
|
-
import { join as
|
|
48462
|
+
import { existsSync as existsSync23, readFileSync as readFileSync23, statSync as statSync7 } from "fs";
|
|
48463
|
+
import { homedir as homedir31 } from "os";
|
|
48464
|
+
import { join as join33 } from "path";
|
|
48245
48465
|
function prefixMatch(modelName) {
|
|
48246
48466
|
for (const [key, pricing] of pricingMap) {
|
|
48247
48467
|
if (modelName.startsWith(key))
|
|
@@ -48279,12 +48499,12 @@ async function warmPricingCache() {
|
|
|
48279
48499
|
}
|
|
48280
48500
|
function loadDiskCache() {
|
|
48281
48501
|
try {
|
|
48282
|
-
if (!
|
|
48502
|
+
if (!existsSync23(CACHE_FILE))
|
|
48283
48503
|
return false;
|
|
48284
48504
|
const stat = statSync7(CACHE_FILE);
|
|
48285
48505
|
const age = Date.now() - stat.mtimeMs;
|
|
48286
48506
|
const isFresh = age < CACHE_TTL_MS3;
|
|
48287
|
-
const raw =
|
|
48507
|
+
const raw = readFileSync23(CACHE_FILE, "utf-8");
|
|
48288
48508
|
const data = JSON.parse(raw);
|
|
48289
48509
|
for (const [key, pricing] of Object.entries(data)) {
|
|
48290
48510
|
pricingMap.set(key, pricing);
|
|
@@ -48300,21 +48520,24 @@ var init_pricing_cache = __esm(() => {
|
|
|
48300
48520
|
init_logger();
|
|
48301
48521
|
init_catalog_query();
|
|
48302
48522
|
pricingMap = new Map;
|
|
48303
|
-
CACHE_DIR =
|
|
48304
|
-
CACHE_FILE =
|
|
48523
|
+
CACHE_DIR = join33(homedir31(), ".claudish");
|
|
48524
|
+
CACHE_FILE = join33(CACHE_DIR, "pricing-cache.json");
|
|
48305
48525
|
CACHE_TTL_MS3 = 24 * 60 * 60 * 1000;
|
|
48306
48526
|
});
|
|
48307
48527
|
|
|
48308
48528
|
// src/proxy-server.ts
|
|
48309
|
-
import { appendFileSync as appendFileSync8, mkdirSync as
|
|
48310
|
-
import { join as
|
|
48529
|
+
import { appendFileSync as appendFileSync8, mkdirSync as mkdirSync15 } from "fs";
|
|
48530
|
+
import { join as join34 } from "path";
|
|
48531
|
+
function isTerminalRoutingFailure(e) {
|
|
48532
|
+
return e instanceof RoutingError || e instanceof CatalogIncompatibleError;
|
|
48533
|
+
}
|
|
48311
48534
|
function maybeCaptureClassifierRequest(c, body) {
|
|
48312
48535
|
if (!process.env.CLAUDISH_CLASSIFIER_DEBUG)
|
|
48313
48536
|
return;
|
|
48314
48537
|
try {
|
|
48315
|
-
const dir =
|
|
48538
|
+
const dir = join34(process.cwd(), "logs");
|
|
48316
48539
|
if (!classifierCaptureDirReady) {
|
|
48317
|
-
|
|
48540
|
+
mkdirSync15(dir, { recursive: true });
|
|
48318
48541
|
classifierCaptureDirReady = true;
|
|
48319
48542
|
}
|
|
48320
48543
|
const record = {
|
|
@@ -48337,7 +48560,7 @@ function maybeCaptureClassifierRequest(c, body) {
|
|
|
48337
48560
|
"x-api-key": c.req.header("x-api-key") ? "<present>" : null
|
|
48338
48561
|
}
|
|
48339
48562
|
};
|
|
48340
|
-
appendFileSync8(
|
|
48563
|
+
appendFileSync8(join34(dir, "classifier-capture.jsonl"), `${JSON.stringify(record)}
|
|
48341
48564
|
`);
|
|
48342
48565
|
} catch {}
|
|
48343
48566
|
}
|
|
@@ -48759,7 +48982,7 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
48759
48982
|
const txt = JSON.stringify(body);
|
|
48760
48983
|
return c.json({ input_tokens: Math.ceil(txt.length / 4) });
|
|
48761
48984
|
} catch (e) {
|
|
48762
|
-
if (e
|
|
48985
|
+
if (isTerminalRoutingFailure(e)) {
|
|
48763
48986
|
return c.json(wrapAnthropicError(400, e.message, "invalid_request_error"), 400);
|
|
48764
48987
|
}
|
|
48765
48988
|
return c.json(wrapAnthropicError(500, String(e)), 500);
|
|
@@ -48779,7 +49002,7 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
48779
49002
|
return await handler.handle(c, body);
|
|
48780
49003
|
} catch (e) {
|
|
48781
49004
|
log(`[Proxy] Error: ${e}`);
|
|
48782
|
-
if (e
|
|
49005
|
+
if (isTerminalRoutingFailure(e)) {
|
|
48783
49006
|
return c.json(wrapAnthropicError(400, e.message, "invalid_request_error"), 400);
|
|
48784
49007
|
}
|
|
48785
49008
|
return c.json(wrapAnthropicError(500, String(e)), 500);
|
|
@@ -48842,6 +49065,7 @@ var init_proxy_server = __esm(() => {
|
|
|
48842
49065
|
init_profile_config();
|
|
48843
49066
|
init_auto_route();
|
|
48844
49067
|
init_catalog_client();
|
|
49068
|
+
init_catalog_compatibility();
|
|
48845
49069
|
init_endpoint_diagnostics();
|
|
48846
49070
|
init_endpoint_registration();
|
|
48847
49071
|
init_model_parser();
|
|
@@ -48864,14 +49088,14 @@ var init_proxy_server = __esm(() => {
|
|
|
48864
49088
|
});
|
|
48865
49089
|
|
|
48866
49090
|
// src/mcp-server.ts
|
|
48867
|
-
import { existsSync as
|
|
48868
|
-
import { homedir as
|
|
48869
|
-
import { dirname as
|
|
49091
|
+
import { existsSync as existsSync24, mkdirSync as mkdirSync16, readFileSync as readFileSync24, readdirSync as readdirSync6, writeFileSync as writeFileSync15 } from "fs";
|
|
49092
|
+
import { homedir as homedir32 } from "os";
|
|
49093
|
+
import { dirname as dirname10, join as join35, resolve as resolve5 } from "path";
|
|
48870
49094
|
import { fileURLToPath } from "url";
|
|
48871
49095
|
async function loadAllModels(forceRefresh = false) {
|
|
48872
|
-
if (!forceRefresh &&
|
|
49096
|
+
if (!forceRefresh && existsSync24(ALL_MODELS_CACHE_PATH2)) {
|
|
48873
49097
|
try {
|
|
48874
|
-
const cacheData = JSON.parse(
|
|
49098
|
+
const cacheData = JSON.parse(readFileSync24(ALL_MODELS_CACHE_PATH2, "utf-8"));
|
|
48875
49099
|
const lastUpdated = new Date(cacheData.lastUpdated);
|
|
48876
49100
|
const ageInDays = (Date.now() - lastUpdated.getTime()) / (1000 * 60 * 60 * 24);
|
|
48877
49101
|
if (ageInDays <= CACHE_MAX_AGE_DAYS) {
|
|
@@ -48885,12 +49109,12 @@ async function loadAllModels(forceRefresh = false) {
|
|
|
48885
49109
|
throw new Error(`API returned ${response.status}`);
|
|
48886
49110
|
const data = await response.json();
|
|
48887
49111
|
const models = data.data || [];
|
|
48888
|
-
|
|
48889
|
-
|
|
49112
|
+
mkdirSync16(CLAUDISH_CACHE_DIR, { recursive: true });
|
|
49113
|
+
writeFileSync15(ALL_MODELS_CACHE_PATH2, JSON.stringify({ lastUpdated: new Date().toISOString(), models }), "utf-8");
|
|
48890
49114
|
return models;
|
|
48891
49115
|
} catch {
|
|
48892
|
-
if (
|
|
48893
|
-
const cacheData = JSON.parse(
|
|
49116
|
+
if (existsSync24(ALL_MODELS_CACHE_PATH2)) {
|
|
49117
|
+
const cacheData = JSON.parse(readFileSync24(ALL_MODELS_CACHE_PATH2, "utf-8"));
|
|
48894
49118
|
return cacheData.models || [];
|
|
48895
49119
|
}
|
|
48896
49120
|
return [];
|
|
@@ -49753,7 +49977,7 @@ Use with: run_prompt(model="${suggested}", prompt="your prompt")`;
|
|
|
49753
49977
|
let stderrFull = stderr_snippet || "";
|
|
49754
49978
|
if (error_log_path) {
|
|
49755
49979
|
try {
|
|
49756
|
-
stderrFull =
|
|
49980
|
+
stderrFull = readFileSync24(error_log_path, "utf-8");
|
|
49757
49981
|
} catch {}
|
|
49758
49982
|
}
|
|
49759
49983
|
const sessionData = {};
|
|
@@ -49761,16 +49985,16 @@ Use with: run_prompt(model="${suggested}", prompt="your prompt")`;
|
|
|
49761
49985
|
const sp = session_path;
|
|
49762
49986
|
for (const file of ["status.json", "manifest.json", "input.md"]) {
|
|
49763
49987
|
try {
|
|
49764
|
-
sessionData[file] =
|
|
49988
|
+
sessionData[file] = readFileSync24(join35(sp, file), "utf-8");
|
|
49765
49989
|
} catch {}
|
|
49766
49990
|
}
|
|
49767
49991
|
try {
|
|
49768
|
-
const errorDir =
|
|
49769
|
-
if (
|
|
49992
|
+
const errorDir = join35(sp, "errors");
|
|
49993
|
+
if (existsSync24(errorDir)) {
|
|
49770
49994
|
for (const f of readdirSync6(errorDir)) {
|
|
49771
49995
|
if (f.endsWith(".log")) {
|
|
49772
49996
|
try {
|
|
49773
|
-
sessionData[`errors/${f}`] =
|
|
49997
|
+
sessionData[`errors/${f}`] = readFileSync24(join35(errorDir, f), "utf-8");
|
|
49774
49998
|
} catch {}
|
|
49775
49999
|
}
|
|
49776
50000
|
}
|
|
@@ -49780,7 +50004,7 @@ Use with: run_prompt(model="${suggested}", prompt="your prompt")`;
|
|
|
49780
50004
|
for (const f of readdirSync6(sp)) {
|
|
49781
50005
|
if (f.startsWith("response-") && f.endsWith(".md")) {
|
|
49782
50006
|
try {
|
|
49783
|
-
const content =
|
|
50007
|
+
const content = readFileSync24(join35(sp, f), "utf-8");
|
|
49784
50008
|
sessionData[f] = content.slice(0, 200) + (content.length > 200 ? "... (truncated)" : "");
|
|
49785
50009
|
} catch {}
|
|
49786
50010
|
}
|
|
@@ -49789,9 +50013,9 @@ Use with: run_prompt(model="${suggested}", prompt="your prompt")`;
|
|
|
49789
50013
|
}
|
|
49790
50014
|
let version = "unknown";
|
|
49791
50015
|
try {
|
|
49792
|
-
const pkgPath =
|
|
49793
|
-
if (
|
|
49794
|
-
version = JSON.parse(
|
|
50016
|
+
const pkgPath = join35(__dirname2, "../package.json");
|
|
50017
|
+
if (existsSync24(pkgPath)) {
|
|
50018
|
+
version = JSON.parse(readFileSync24(pkgPath, "utf-8")).version;
|
|
49795
50019
|
}
|
|
49796
50020
|
} catch {}
|
|
49797
50021
|
const report = {
|
|
@@ -50258,9 +50482,9 @@ var init_mcp_server = __esm(() => {
|
|
|
50258
50482
|
import_dotenv2 = __toESM(require_main(), 1);
|
|
50259
50483
|
import_dotenv2.config({ quiet: true });
|
|
50260
50484
|
__filename2 = fileURLToPath(import.meta.url);
|
|
50261
|
-
__dirname2 =
|
|
50262
|
-
CLAUDISH_CACHE_DIR =
|
|
50263
|
-
ALL_MODELS_CACHE_PATH2 =
|
|
50485
|
+
__dirname2 = dirname10(__filename2);
|
|
50486
|
+
CLAUDISH_CACHE_DIR = join35(homedir32(), ".claudish");
|
|
50487
|
+
ALL_MODELS_CACHE_PATH2 = join35(CLAUDISH_CACHE_DIR, "all-models.json");
|
|
50264
50488
|
NEXT_STEP = {
|
|
50265
50489
|
nonzero_exit: "read the evidence log, then retry or drop the model",
|
|
50266
50490
|
cancelled: "you stopped this slot; nothing is wrong with it. Re-run it if you still want its vote",
|
|
@@ -50284,7 +50508,7 @@ var init_mcp_server = __esm(() => {
|
|
|
50284
50508
|
});
|
|
50285
50509
|
|
|
50286
50510
|
// src/serve-command.ts
|
|
50287
|
-
import { existsSync as
|
|
50511
|
+
import { existsSync as existsSync25, readFileSync as readFileSync25 } from "fs";
|
|
50288
50512
|
function parseServeArgs(args) {
|
|
50289
50513
|
const out = {};
|
|
50290
50514
|
for (let i = 0;i < args.length; i++) {
|
|
@@ -50303,12 +50527,12 @@ function parseServeArgs(args) {
|
|
|
50303
50527
|
return out;
|
|
50304
50528
|
}
|
|
50305
50529
|
function loadModelMap(path) {
|
|
50306
|
-
if (!
|
|
50530
|
+
if (!existsSync25(path)) {
|
|
50307
50531
|
throw new Error(`--models file not found: ${path}`);
|
|
50308
50532
|
}
|
|
50309
50533
|
let raw;
|
|
50310
50534
|
try {
|
|
50311
|
-
raw =
|
|
50535
|
+
raw = readFileSync25(path, "utf-8");
|
|
50312
50536
|
} catch (e) {
|
|
50313
50537
|
throw new Error(`failed to read --models file ${path}: ${e instanceof Error ? e.message : String(e)}`);
|
|
50314
50538
|
}
|
|
@@ -50588,7 +50812,7 @@ var init_ansi = __esm(() => {
|
|
|
50588
50812
|
});
|
|
50589
50813
|
|
|
50590
50814
|
// src/behavior-command.ts
|
|
50591
|
-
import { existsSync as
|
|
50815
|
+
import { existsSync as existsSync26, readFileSync as readFileSync26, writeFileSync as writeFileSync16 } from "fs";
|
|
50592
50816
|
function severityColor(sev) {
|
|
50593
50817
|
if (sev === "fix")
|
|
50594
50818
|
return green(sev);
|
|
@@ -50686,8 +50910,8 @@ function setTelemetryEnabled(value) {
|
|
|
50686
50910
|
const path = getConfigPath();
|
|
50687
50911
|
let cfg = {};
|
|
50688
50912
|
try {
|
|
50689
|
-
if (
|
|
50690
|
-
const parsed = JSON.parse(
|
|
50913
|
+
if (existsSync26(path)) {
|
|
50914
|
+
const parsed = JSON.parse(readFileSync26(path, "utf-8"));
|
|
50691
50915
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
50692
50916
|
cfg = parsed;
|
|
50693
50917
|
}
|
|
@@ -50696,7 +50920,7 @@ function setTelemetryEnabled(value) {
|
|
|
50696
50920
|
const behavior = cfg.behavior && typeof cfg.behavior === "object" && !Array.isArray(cfg.behavior) ? { ...cfg.behavior } : {};
|
|
50697
50921
|
behavior.telemetry = { enabled: value };
|
|
50698
50922
|
cfg.behavior = behavior;
|
|
50699
|
-
|
|
50923
|
+
writeFileSync16(path, `${JSON.stringify(cfg, null, 2)}
|
|
50700
50924
|
`, "utf-8");
|
|
50701
50925
|
}
|
|
50702
50926
|
function showTelemetry(action, json) {
|
|
@@ -50708,8 +50932,8 @@ function showTelemetry(action, json) {
|
|
|
50708
50932
|
let pending = 0;
|
|
50709
50933
|
try {
|
|
50710
50934
|
const path = outboxPath();
|
|
50711
|
-
if (
|
|
50712
|
-
pending =
|
|
50935
|
+
if (existsSync26(path)) {
|
|
50936
|
+
pending = readFileSync26(path, "utf8").split(`
|
|
50713
50937
|
`).filter(Boolean).length;
|
|
50714
50938
|
}
|
|
50715
50939
|
} catch {}
|
|
@@ -50790,9 +51014,9 @@ var init_behavior_command = __esm(() => {
|
|
|
50790
51014
|
// src/team-grid.ts
|
|
50791
51015
|
import { spawn as spawn4 } from "child_process";
|
|
50792
51016
|
import { execSync } from "child_process";
|
|
50793
|
-
import { existsSync as
|
|
51017
|
+
import { existsSync as existsSync27, readFileSync as readFileSync27, writeFileSync as writeFileSync17 } from "fs";
|
|
50794
51018
|
import { connect as netConnect } from "net";
|
|
50795
|
-
import { dirname as
|
|
51019
|
+
import { dirname as dirname11, join as join36 } from "path";
|
|
50796
51020
|
import { setTimeout as wait } from "timers/promises";
|
|
50797
51021
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
50798
51022
|
function resolveRouteInfo(modelId) {
|
|
@@ -50885,21 +51109,21 @@ function buildPaneHeader(model, prompt, bg) {
|
|
|
50885
51109
|
}
|
|
50886
51110
|
function findMagmuxBinary() {
|
|
50887
51111
|
const thisFile = fileURLToPath2(import.meta.url);
|
|
50888
|
-
const thisDir =
|
|
50889
|
-
const pkgRoot =
|
|
51112
|
+
const thisDir = dirname11(thisFile);
|
|
51113
|
+
const pkgRoot = join36(thisDir, "..");
|
|
50890
51114
|
const platform = process.platform;
|
|
50891
51115
|
const arch = process.arch;
|
|
50892
|
-
const bundledMagmux =
|
|
50893
|
-
if (
|
|
51116
|
+
const bundledMagmux = join36(pkgRoot, "native", `magmux-${platform}-${arch}`);
|
|
51117
|
+
if (existsSync27(bundledMagmux))
|
|
50894
51118
|
return bundledMagmux;
|
|
50895
51119
|
try {
|
|
50896
51120
|
const pkgName = `@claudish/magmux-${platform}-${arch}`;
|
|
50897
51121
|
let searchDir = pkgRoot;
|
|
50898
51122
|
for (let i = 0;i < 5; i++) {
|
|
50899
|
-
const candidate =
|
|
50900
|
-
if (
|
|
51123
|
+
const candidate = join36(searchDir, "node_modules", pkgName, "bin", "magmux");
|
|
51124
|
+
if (existsSync27(candidate))
|
|
50901
51125
|
return candidate;
|
|
50902
|
-
const parent =
|
|
51126
|
+
const parent = dirname11(searchDir);
|
|
50903
51127
|
if (parent === searchDir)
|
|
50904
51128
|
break;
|
|
50905
51129
|
searchDir = parent;
|
|
@@ -50921,7 +51145,7 @@ function withoutControlPanes(evt) {
|
|
|
50921
51145
|
async function subscribeToMagmux(sockPath, onEvent) {
|
|
50922
51146
|
let client = null;
|
|
50923
51147
|
for (let attempt = 0;attempt < 40; attempt++) {
|
|
50924
|
-
if (
|
|
51148
|
+
if (existsSync27(sockPath)) {
|
|
50925
51149
|
try {
|
|
50926
51150
|
client = await new Promise((resolve, reject) => {
|
|
50927
51151
|
const s = netConnect(sockPath);
|
|
@@ -51008,9 +51232,9 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
51008
51232
|
const keep = opts?.keep ?? false;
|
|
51009
51233
|
const manifest = setupSession(sessionPath, models, input);
|
|
51010
51234
|
const startedAt = new Date().toISOString();
|
|
51011
|
-
const gridfilePath =
|
|
51012
|
-
const prompt =
|
|
51013
|
-
const rawPrompt =
|
|
51235
|
+
const gridfilePath = join36(sessionPath, "gridfile.txt");
|
|
51236
|
+
const prompt = readFileSync27(join36(sessionPath, "input.md"), "utf-8").replace(/'/g, "'\\''").replace(/\n/g, " ");
|
|
51237
|
+
const rawPrompt = readFileSync27(join36(sessionPath, "input.md"), "utf-8");
|
|
51014
51238
|
const usedBannerColors = new Set;
|
|
51015
51239
|
const gridLines = Object.entries(manifest.models).map(([anonId]) => {
|
|
51016
51240
|
const model = manifest.models[anonId].model;
|
|
@@ -51021,7 +51245,7 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
51021
51245
|
const header = buildPaneHeader(model, rawPrompt, bg);
|
|
51022
51246
|
return `${header} claudish --model ${model} -y --quiet '${prompt}'`;
|
|
51023
51247
|
});
|
|
51024
|
-
|
|
51248
|
+
writeFileSync17(gridfilePath, `${gridLines.join(`
|
|
51025
51249
|
`)}
|
|
51026
51250
|
`, "utf-8");
|
|
51027
51251
|
const magmuxPath = findMagmuxBinary();
|
|
@@ -51041,8 +51265,8 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
51041
51265
|
});
|
|
51042
51266
|
const [{ results }] = await Promise.all([subscription, procExit]);
|
|
51043
51267
|
const status = buildTeamStatus(manifest, startedAt, results?.panes ?? null);
|
|
51044
|
-
const statusPath =
|
|
51045
|
-
|
|
51268
|
+
const statusPath = join36(sessionPath, "status.json");
|
|
51269
|
+
writeFileSync17(statusPath, JSON.stringify(status, null, 2), "utf-8");
|
|
51046
51270
|
return status;
|
|
51047
51271
|
}
|
|
51048
51272
|
var BANNER_BG_COLORS;
|
|
@@ -51062,8 +51286,8 @@ var init_team_grid = __esm(() => {
|
|
|
51062
51286
|
});
|
|
51063
51287
|
|
|
51064
51288
|
// src/team-cli.ts
|
|
51065
|
-
import { readFileSync as
|
|
51066
|
-
import { join as
|
|
51289
|
+
import { readFileSync as readFileSync28 } from "fs";
|
|
51290
|
+
import { join as join37 } from "path";
|
|
51067
51291
|
function getFlag(args, flag) {
|
|
51068
51292
|
const idx = args.indexOf(flag);
|
|
51069
51293
|
if (idx === -1 || idx + 1 >= args.length)
|
|
@@ -51186,7 +51410,7 @@ async function teamCommand(args) {
|
|
|
51186
51410
|
}
|
|
51187
51411
|
case "judge": {
|
|
51188
51412
|
await judgeResponses(sessionPath, { judges });
|
|
51189
|
-
console.log(
|
|
51413
|
+
console.log(readFileSync28(join37(sessionPath, "verdict.md"), "utf-8"));
|
|
51190
51414
|
break;
|
|
51191
51415
|
}
|
|
51192
51416
|
case "run-and-judge": {
|
|
@@ -51203,7 +51427,7 @@ async function teamCommand(args) {
|
|
|
51203
51427
|
});
|
|
51204
51428
|
printStatus(status);
|
|
51205
51429
|
await judgeResponses(sessionPath, { judges });
|
|
51206
|
-
console.log(
|
|
51430
|
+
console.log(readFileSync28(join37(sessionPath, "verdict.md"), "utf-8"));
|
|
51207
51431
|
break;
|
|
51208
51432
|
}
|
|
51209
51433
|
case "status": {
|
|
@@ -54027,9 +54251,9 @@ var init_keychain_command = __esm(() => {
|
|
|
54027
54251
|
|
|
54028
54252
|
// src/auth/antigravity-oauth.ts
|
|
54029
54253
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
54030
|
-
import { existsSync as
|
|
54031
|
-
import { homedir as
|
|
54032
|
-
import { join as
|
|
54254
|
+
import { existsSync as existsSync28, unlinkSync as unlinkSync6 } from "fs";
|
|
54255
|
+
import { homedir as homedir33 } from "os";
|
|
54256
|
+
import { join as join38 } from "path";
|
|
54033
54257
|
async function defaultSuggestModel() {
|
|
54034
54258
|
try {
|
|
54035
54259
|
const tok = readSharedAntigravityToken();
|
|
@@ -54150,8 +54374,8 @@ No session detected yet. Starting the Antigravity CLI interactively \u2014
|
|
|
54150
54374
|
async logout(deps) {
|
|
54151
54375
|
deleteSharedAntigravityToken(deps);
|
|
54152
54376
|
try {
|
|
54153
|
-
const tokenFile =
|
|
54154
|
-
if (
|
|
54377
|
+
const tokenFile = join38(homedir33(), ".gemini", "antigravity-cli", "antigravity-oauth-token");
|
|
54378
|
+
if (existsSync28(tokenFile))
|
|
54155
54379
|
unlinkSync6(tokenFile);
|
|
54156
54380
|
} catch {}
|
|
54157
54381
|
log("[AntigravityOAuth] Antigravity session cleared (keychain + agy token file)");
|
|
@@ -57942,6 +58166,51 @@ var init_api_key_map = __esm(() => {
|
|
|
57942
58166
|
};
|
|
57943
58167
|
});
|
|
57944
58168
|
|
|
58169
|
+
// src/providers/provider-slug-resolve.ts
|
|
58170
|
+
function sharedPrefixLength(a, b) {
|
|
58171
|
+
let n = 0;
|
|
58172
|
+
while (n < a.length && n < b.length && a[n] === b[n])
|
|
58173
|
+
n++;
|
|
58174
|
+
return n;
|
|
58175
|
+
}
|
|
58176
|
+
function rankSuggestions(typed, providers) {
|
|
58177
|
+
const needle = typed.toLowerCase();
|
|
58178
|
+
const scored = [];
|
|
58179
|
+
for (const provider of providers) {
|
|
58180
|
+
const slug = provider.slug.toLowerCase();
|
|
58181
|
+
let score = 0;
|
|
58182
|
+
if (slug.includes(needle) || needle.includes(slug)) {
|
|
58183
|
+
score = 2;
|
|
58184
|
+
} else if (sharedPrefixLength(slug, needle) >= MIN_PREFIX_OVERLAP) {
|
|
58185
|
+
score = 1;
|
|
58186
|
+
}
|
|
58187
|
+
if (score > 0)
|
|
58188
|
+
scored.push({ provider, score });
|
|
58189
|
+
}
|
|
58190
|
+
scored.sort((a, b) => b.score - a.score || b.provider.count - a.provider.count);
|
|
58191
|
+
return scored.slice(0, SUGGESTION_LIMIT).map((s) => s.provider);
|
|
58192
|
+
}
|
|
58193
|
+
function resolveProviderSlug(typed, providers) {
|
|
58194
|
+
const routingOwner = reservedNamespaceOwner(typed) ?? null;
|
|
58195
|
+
if (providers.length === 0) {
|
|
58196
|
+
return { kind: "match", canonical: typed, suggestions: [], routingOwner };
|
|
58197
|
+
}
|
|
58198
|
+
const exact = providers.find((p) => p.slug.toLowerCase() === typed.toLowerCase());
|
|
58199
|
+
if (exact) {
|
|
58200
|
+
return { kind: "match", canonical: exact.slug, suggestions: [], routingOwner };
|
|
58201
|
+
}
|
|
58202
|
+
return {
|
|
58203
|
+
kind: "unknown",
|
|
58204
|
+
canonical: null,
|
|
58205
|
+
suggestions: rankSuggestions(typed, providers),
|
|
58206
|
+
routingOwner
|
|
58207
|
+
};
|
|
58208
|
+
}
|
|
58209
|
+
var SUGGESTION_LIMIT = 5, MIN_PREFIX_OVERLAP = 3;
|
|
58210
|
+
var init_provider_slug_resolve = __esm(() => {
|
|
58211
|
+
init_reserved_namespace();
|
|
58212
|
+
});
|
|
58213
|
+
|
|
57945
58214
|
// src/branding.ts
|
|
57946
58215
|
function paint(line) {
|
|
57947
58216
|
const { RESET, BOLD, CYAN, BLUE, DIM } = cliAnsi();
|
|
@@ -58000,33 +58269,33 @@ var init_branding = __esm(() => {
|
|
|
58000
58269
|
});
|
|
58001
58270
|
|
|
58002
58271
|
// src/update-checker.ts
|
|
58003
|
-
import { existsSync as
|
|
58004
|
-
import { homedir as
|
|
58005
|
-
import { join as
|
|
58272
|
+
import { existsSync as existsSync29, mkdirSync as mkdirSync17, readFileSync as readFileSync29, unlinkSync as unlinkSync7, writeFileSync as writeFileSync18 } from "fs";
|
|
58273
|
+
import { homedir as homedir34, platform as platform2, tmpdir } from "os";
|
|
58274
|
+
import { join as join39 } from "path";
|
|
58006
58275
|
function getCacheFilePath() {
|
|
58007
58276
|
let cacheDir;
|
|
58008
58277
|
if (isWindows) {
|
|
58009
|
-
const localAppData = process.env.LOCALAPPDATA ||
|
|
58010
|
-
cacheDir =
|
|
58278
|
+
const localAppData = process.env.LOCALAPPDATA || join39(homedir34(), "AppData", "Local");
|
|
58279
|
+
cacheDir = join39(localAppData, "claudish");
|
|
58011
58280
|
} else {
|
|
58012
|
-
cacheDir =
|
|
58281
|
+
cacheDir = join39(homedir34(), ".cache", "claudish");
|
|
58013
58282
|
}
|
|
58014
58283
|
try {
|
|
58015
|
-
if (!
|
|
58016
|
-
|
|
58284
|
+
if (!existsSync29(cacheDir)) {
|
|
58285
|
+
mkdirSync17(cacheDir, { recursive: true });
|
|
58017
58286
|
}
|
|
58018
|
-
return
|
|
58287
|
+
return join39(cacheDir, "update-check.json");
|
|
58019
58288
|
} catch {
|
|
58020
|
-
return
|
|
58289
|
+
return join39(tmpdir(), "claudish-update-check.json");
|
|
58021
58290
|
}
|
|
58022
58291
|
}
|
|
58023
58292
|
function readCache() {
|
|
58024
58293
|
try {
|
|
58025
58294
|
const cachePath = getCacheFilePath();
|
|
58026
|
-
if (!
|
|
58295
|
+
if (!existsSync29(cachePath)) {
|
|
58027
58296
|
return null;
|
|
58028
58297
|
}
|
|
58029
|
-
const data = JSON.parse(
|
|
58298
|
+
const data = JSON.parse(readFileSync29(cachePath, "utf-8"));
|
|
58030
58299
|
return data;
|
|
58031
58300
|
} catch {
|
|
58032
58301
|
return null;
|
|
@@ -58039,7 +58308,7 @@ function writeCache(latestVersion) {
|
|
|
58039
58308
|
lastCheck: Date.now(),
|
|
58040
58309
|
latestVersion
|
|
58041
58310
|
};
|
|
58042
|
-
|
|
58311
|
+
writeFileSync18(cachePath, JSON.stringify(data), "utf-8");
|
|
58043
58312
|
} catch {}
|
|
58044
58313
|
}
|
|
58045
58314
|
function isCacheValid(cache) {
|
|
@@ -58049,7 +58318,7 @@ function isCacheValid(cache) {
|
|
|
58049
58318
|
function clearCache() {
|
|
58050
58319
|
try {
|
|
58051
58320
|
const cachePath = getCacheFilePath();
|
|
58052
|
-
if (
|
|
58321
|
+
if (existsSync29(cachePath)) {
|
|
58053
58322
|
unlinkSync7(cachePath);
|
|
58054
58323
|
}
|
|
58055
58324
|
} catch {}
|
|
@@ -58134,22 +58403,22 @@ var init_update_checker = __esm(() => {
|
|
|
58134
58403
|
// src/cli.ts
|
|
58135
58404
|
import {
|
|
58136
58405
|
copyFileSync as copyFileSync2,
|
|
58137
|
-
existsSync as
|
|
58138
|
-
mkdirSync as
|
|
58139
|
-
readFileSync as
|
|
58406
|
+
existsSync as existsSync30,
|
|
58407
|
+
mkdirSync as mkdirSync18,
|
|
58408
|
+
readFileSync as readFileSync30,
|
|
58140
58409
|
readdirSync as readdirSync7,
|
|
58141
58410
|
unlinkSync as unlinkSync8,
|
|
58142
|
-
writeFileSync as
|
|
58411
|
+
writeFileSync as writeFileSync19
|
|
58143
58412
|
} from "fs";
|
|
58144
|
-
import { homedir as
|
|
58145
|
-
import { dirname as
|
|
58413
|
+
import { homedir as homedir35 } from "os";
|
|
58414
|
+
import { dirname as dirname12, join as join40 } from "path";
|
|
58146
58415
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
58147
58416
|
function getVersion3() {
|
|
58148
58417
|
return VERSION;
|
|
58149
58418
|
}
|
|
58150
58419
|
function clearAllModelCaches() {
|
|
58151
|
-
const cacheDir =
|
|
58152
|
-
if (!
|
|
58420
|
+
const cacheDir = join40(homedir35(), ".claudish");
|
|
58421
|
+
if (!existsSync30(cacheDir))
|
|
58153
58422
|
return;
|
|
58154
58423
|
const cachePatterns = ["pricing-cache.json", "recommended-models-cache.json"];
|
|
58155
58424
|
let cleared = 0;
|
|
@@ -58157,7 +58426,7 @@ function clearAllModelCaches() {
|
|
|
58157
58426
|
const files = readdirSync7(cacheDir);
|
|
58158
58427
|
for (const file of files) {
|
|
58159
58428
|
if (cachePatterns.includes(file)) {
|
|
58160
|
-
unlinkSync8(
|
|
58429
|
+
unlinkSync8(join40(cacheDir, file));
|
|
58161
58430
|
cleared++;
|
|
58162
58431
|
}
|
|
58163
58432
|
}
|
|
@@ -58512,7 +58781,19 @@ Usage: claudish --models --provider <slug>`);
|
|
|
58512
58781
|
const hasJsonFlag = args.includes("--json");
|
|
58513
58782
|
const forceUpdate = config.forceUpdate || args.includes("--models-refresh");
|
|
58514
58783
|
const providerIdx = args.indexOf("--provider");
|
|
58515
|
-
const
|
|
58784
|
+
const inlineProvider = args.find((a) => a.startsWith("--provider="));
|
|
58785
|
+
let providerSlug = null;
|
|
58786
|
+
if (inlineProvider) {
|
|
58787
|
+
providerSlug = inlineProvider.slice("--provider=".length);
|
|
58788
|
+
} else if (providerIdx !== -1) {
|
|
58789
|
+
const next = args[providerIdx + 1];
|
|
58790
|
+
providerSlug = next && !next.startsWith("--") ? next : "";
|
|
58791
|
+
}
|
|
58792
|
+
if (providerSlug === "") {
|
|
58793
|
+
console.error("--provider needs a slug: claudish --models --provider <slug>");
|
|
58794
|
+
console.error("Run `claudish --providers` for the full list.");
|
|
58795
|
+
process.exit(1);
|
|
58796
|
+
}
|
|
58516
58797
|
if (forceUpdate)
|
|
58517
58798
|
clearAllModelCaches();
|
|
58518
58799
|
if (query && providerSlug) {
|
|
@@ -58619,15 +58900,15 @@ Usage: claudish --models --provider <slug>`);
|
|
|
58619
58900
|
});
|
|
58620
58901
|
config.resolvedDefaultProvider = resolved;
|
|
58621
58902
|
if (resolved.legacyAutoPromoted && !config.quiet) {
|
|
58622
|
-
const markerFile =
|
|
58623
|
-
if (!
|
|
58903
|
+
const markerFile = join40(homedir35(), ".claudish", ".legacy-litellm-hint-shown");
|
|
58904
|
+
if (!existsSync30(markerFile)) {
|
|
58624
58905
|
const hint = buildLegacyHint(resolved);
|
|
58625
58906
|
if (hint) {
|
|
58626
58907
|
console.error(hint);
|
|
58627
58908
|
}
|
|
58628
58909
|
try {
|
|
58629
|
-
|
|
58630
|
-
|
|
58910
|
+
mkdirSync18(dirname12(markerFile), { recursive: true });
|
|
58911
|
+
writeFileSync19(markerFile, new Date().toISOString(), "utf-8");
|
|
58631
58912
|
} catch {}
|
|
58632
58913
|
}
|
|
58633
58914
|
}
|
|
@@ -58787,7 +59068,46 @@ Top ${response.total} models from Firebase (pool: ${response.poolSize} eligible)
|
|
|
58787
59068
|
console.log("Top recommended: claudish --models-top");
|
|
58788
59069
|
console.log("");
|
|
58789
59070
|
}
|
|
58790
|
-
|
|
59071
|
+
function printUnknownProviderSlug(typedSlug, resolved, catalogSize, jsonOutput) {
|
|
59072
|
+
if (jsonOutput) {
|
|
59073
|
+
console.log(JSON.stringify({
|
|
59074
|
+
error: `"${typedSlug}" is not a provider slug in the model catalog`,
|
|
59075
|
+
provider: typedSlug,
|
|
59076
|
+
suggestions: resolved.suggestions.map((s) => s.slug),
|
|
59077
|
+
routingPrefixOwner: resolved.routingOwner,
|
|
59078
|
+
validSlugs: catalogSize
|
|
59079
|
+
}, null, 2));
|
|
59080
|
+
return;
|
|
59081
|
+
}
|
|
59082
|
+
console.error(`
|
|
59083
|
+
\u274C "${typedSlug}" is not a provider slug in the model catalog.`);
|
|
59084
|
+
if (resolved.suggestions.length > 0) {
|
|
59085
|
+
const list = resolved.suggestions.map((s) => `${s.slug} (${s.count} active model${s.count === 1 ? "" : "s"})`).join(", ");
|
|
59086
|
+
console.error(`
|
|
59087
|
+
Did you mean: ${list}`);
|
|
59088
|
+
}
|
|
59089
|
+
if (resolved.routingOwner) {
|
|
59090
|
+
console.error(`
|
|
59091
|
+
"${typedSlug}" IS a claudish routing prefix for the "${resolved.routingOwner}" provider \u2014` + `
|
|
59092
|
+
use it with --model: claudish --model ${typedSlug}@<model-id>` + `
|
|
59093
|
+
Routing prefixes and catalog vendor slugs are different vocabularies.`);
|
|
59094
|
+
}
|
|
59095
|
+
console.error(`
|
|
59096
|
+
claudish --providers lists all ${catalogSize} catalog slugs`);
|
|
59097
|
+
console.error(` claudish -s ${typedSlug}${" ".repeat(Math.max(1, 12 - typedSlug.length))}searches model ids instead
|
|
59098
|
+
`);
|
|
59099
|
+
}
|
|
59100
|
+
async function printByProvider(typedSlug, jsonOutput) {
|
|
59101
|
+
let catalogProviders = [];
|
|
59102
|
+
try {
|
|
59103
|
+
catalogProviders = await getProviderList();
|
|
59104
|
+
} catch {}
|
|
59105
|
+
const resolved = resolveProviderSlug(typedSlug, catalogProviders);
|
|
59106
|
+
if (resolved.kind === "unknown") {
|
|
59107
|
+
printUnknownProviderSlug(typedSlug, resolved, catalogProviders.length, jsonOutput);
|
|
59108
|
+
process.exit(1);
|
|
59109
|
+
}
|
|
59110
|
+
const providerSlug = resolved.canonical ?? typedSlug;
|
|
58791
59111
|
let models;
|
|
58792
59112
|
try {
|
|
58793
59113
|
models = await getModelsByProvider(providerSlug, 200);
|
|
@@ -58802,8 +59122,8 @@ async function printByProvider(providerSlug, jsonOutput) {
|
|
|
58802
59122
|
}
|
|
58803
59123
|
if (models.length === 0) {
|
|
58804
59124
|
console.log(`
|
|
58805
|
-
|
|
58806
|
-
`);
|
|
59125
|
+
Provider "${providerSlug}" is in the catalog but has no active models right now.`);
|
|
59126
|
+
console.log("Try `claudish -s <query>` to search the full catalog.\n");
|
|
58807
59127
|
return;
|
|
58808
59128
|
}
|
|
58809
59129
|
console.log(`
|
|
@@ -59764,8 +60084,8 @@ ${h("MORE INFO")}
|
|
|
59764
60084
|
}
|
|
59765
60085
|
function printAIAgentGuide() {
|
|
59766
60086
|
try {
|
|
59767
|
-
const guidePath =
|
|
59768
|
-
const guideContent =
|
|
60087
|
+
const guidePath = join40(__dirname3, "../AI_AGENT_GUIDE.md");
|
|
60088
|
+
const guideContent = readFileSync30(guidePath, "utf-8");
|
|
59769
60089
|
console.log(guideContent);
|
|
59770
60090
|
} catch (error) {
|
|
59771
60091
|
console.error("Error reading AI Agent Guide:");
|
|
@@ -59781,19 +60101,19 @@ async function initializeClaudishSkill() {
|
|
|
59781
60101
|
console.log(`\uD83D\uDD27 Initializing Claudish skill in current project...
|
|
59782
60102
|
`);
|
|
59783
60103
|
const cwd = process.cwd();
|
|
59784
|
-
const claudeDir =
|
|
59785
|
-
const skillsDir =
|
|
59786
|
-
const claudishSkillDir =
|
|
59787
|
-
const skillFile =
|
|
59788
|
-
if (
|
|
60104
|
+
const claudeDir = join40(cwd, ".claude");
|
|
60105
|
+
const skillsDir = join40(claudeDir, "skills");
|
|
60106
|
+
const claudishSkillDir = join40(skillsDir, "claudish-usage");
|
|
60107
|
+
const skillFile = join40(claudishSkillDir, "SKILL.md");
|
|
60108
|
+
if (existsSync30(skillFile)) {
|
|
59789
60109
|
console.log("\u2705 Claudish skill already installed at:");
|
|
59790
60110
|
console.log(` ${skillFile}
|
|
59791
60111
|
`);
|
|
59792
60112
|
console.log("\uD83D\uDCA1 To reinstall, delete the file and run 'claudish --init' again.");
|
|
59793
60113
|
return;
|
|
59794
60114
|
}
|
|
59795
|
-
const sourceSkillPath =
|
|
59796
|
-
if (!
|
|
60115
|
+
const sourceSkillPath = join40(__dirname3, "../skills/claudish-usage/SKILL.md");
|
|
60116
|
+
if (!existsSync30(sourceSkillPath)) {
|
|
59797
60117
|
console.error("\u274C Error: Claudish skill file not found in installation.");
|
|
59798
60118
|
console.error(` Expected at: ${sourceSkillPath}`);
|
|
59799
60119
|
console.error(`
|
|
@@ -59802,16 +60122,16 @@ async function initializeClaudishSkill() {
|
|
|
59802
60122
|
process.exit(1);
|
|
59803
60123
|
}
|
|
59804
60124
|
try {
|
|
59805
|
-
if (!
|
|
59806
|
-
|
|
60125
|
+
if (!existsSync30(claudeDir)) {
|
|
60126
|
+
mkdirSync18(claudeDir, { recursive: true });
|
|
59807
60127
|
console.log("\uD83D\uDCC1 Created .claude/ directory");
|
|
59808
60128
|
}
|
|
59809
|
-
if (!
|
|
59810
|
-
|
|
60129
|
+
if (!existsSync30(skillsDir)) {
|
|
60130
|
+
mkdirSync18(skillsDir, { recursive: true });
|
|
59811
60131
|
console.log("\uD83D\uDCC1 Created .claude/skills/ directory");
|
|
59812
60132
|
}
|
|
59813
|
-
if (!
|
|
59814
|
-
|
|
60133
|
+
if (!existsSync30(claudishSkillDir)) {
|
|
60134
|
+
mkdirSync18(claudishSkillDir, { recursive: true });
|
|
59815
60135
|
console.log("\uD83D\uDCC1 Created .claude/skills/claudish-usage/ directory");
|
|
59816
60136
|
}
|
|
59817
60137
|
copyFileSync2(sourceSkillPath, skillFile);
|
|
@@ -59884,11 +60204,12 @@ var init_cli = __esm(() => {
|
|
|
59884
60204
|
init_probe_live();
|
|
59885
60205
|
init_probe_runner();
|
|
59886
60206
|
init_provider_definitions();
|
|
60207
|
+
init_provider_slug_resolve();
|
|
59887
60208
|
init_routing_rules();
|
|
59888
60209
|
init_ansi();
|
|
59889
60210
|
init_provider_resolver();
|
|
59890
60211
|
__filename3 = fileURLToPath3(import.meta.url);
|
|
59891
|
-
__dirname3 =
|
|
60212
|
+
__dirname3 = dirname12(__filename3);
|
|
59892
60213
|
});
|
|
59893
60214
|
|
|
59894
60215
|
// src/update-command.ts
|
|
@@ -60707,15 +61028,15 @@ var init_local_liveness = __esm(() => {
|
|
|
60707
61028
|
});
|
|
60708
61029
|
|
|
60709
61030
|
// src/providers/probe-catalog.ts
|
|
60710
|
-
import { existsSync as
|
|
60711
|
-
import { homedir as
|
|
60712
|
-
import { dirname as
|
|
61031
|
+
import { existsSync as existsSync31, mkdirSync as mkdirSync19, readFileSync as readFileSync31, writeFileSync as writeFileSync20 } from "fs";
|
|
61032
|
+
import { homedir as homedir36 } from "os";
|
|
61033
|
+
import { dirname as dirname13, join as join41 } from "path";
|
|
60713
61034
|
function readProbeModelsCache(path = PROBE_MODELS_CACHE_PATH) {
|
|
60714
|
-
if (!
|
|
61035
|
+
if (!existsSync31(path))
|
|
60715
61036
|
return null;
|
|
60716
61037
|
let raw;
|
|
60717
61038
|
try {
|
|
60718
|
-
raw = JSON.parse(
|
|
61039
|
+
raw = JSON.parse(readFileSync31(path, "utf-8"));
|
|
60719
61040
|
} catch {
|
|
60720
61041
|
return null;
|
|
60721
61042
|
}
|
|
@@ -60724,8 +61045,8 @@ function readProbeModelsCache(path = PROBE_MODELS_CACHE_PATH) {
|
|
|
60724
61045
|
return raw;
|
|
60725
61046
|
}
|
|
60726
61047
|
function writeProbeModelsCache(data, path = PROBE_MODELS_CACHE_PATH) {
|
|
60727
|
-
|
|
60728
|
-
|
|
61048
|
+
mkdirSync19(dirname13(path), { recursive: true });
|
|
61049
|
+
writeFileSync20(path, JSON.stringify(data), "utf-8");
|
|
60729
61050
|
}
|
|
60730
61051
|
function isCacheFresh(data, ttlMs = CACHE_TTL_MS4) {
|
|
60731
61052
|
if (!data?.generatedAt)
|
|
@@ -60844,7 +61165,7 @@ function isValidResponse(raw) {
|
|
|
60844
61165
|
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;
|
|
60845
61166
|
var init_probe_catalog = __esm(() => {
|
|
60846
61167
|
CACHE_TTL_MS4 = 60 * 60 * 1000;
|
|
60847
|
-
PROBE_MODELS_CACHE_PATH =
|
|
61168
|
+
PROBE_MODELS_CACHE_PATH = join41(homedir36(), ".claudish", "probe-models.json");
|
|
60848
61169
|
});
|
|
60849
61170
|
|
|
60850
61171
|
// src/tui/constants.ts
|
|
@@ -65312,6 +65633,13 @@ var probeProxy = null, probeProxyStarting = null;
|
|
|
65312
65633
|
|
|
65313
65634
|
// src/tui/hooks/useRouteProbe.ts
|
|
65314
65635
|
import { useCallback as useCallback2, useState as useState4 } from "react";
|
|
65636
|
+
async function routeForProbe(model) {
|
|
65637
|
+
try {
|
|
65638
|
+
return await route(model);
|
|
65639
|
+
} catch (err) {
|
|
65640
|
+
return { kind: "no-route", reason: err instanceof Error ? err.message : String(err) };
|
|
65641
|
+
}
|
|
65642
|
+
}
|
|
65315
65643
|
function useRouteProbe(config) {
|
|
65316
65644
|
const [probeMode, setProbeMode] = useState4("idle");
|
|
65317
65645
|
const [probeModel, setProbeModel] = useState4("");
|
|
@@ -65350,7 +65678,7 @@ function useRouteProbe(config) {
|
|
|
65350
65678
|
if (native) {
|
|
65351
65679
|
chain = [native];
|
|
65352
65680
|
} else {
|
|
65353
|
-
const plan = await
|
|
65681
|
+
const plan = await routeForProbe(model);
|
|
65354
65682
|
if (plan.kind !== "ok") {
|
|
65355
65683
|
setProbeResults([
|
|
65356
65684
|
{
|
|
@@ -67462,17 +67790,17 @@ var init_terminal_isolation = __esm(() => {
|
|
|
67462
67790
|
import { spawn as spawn5, spawnSync as spawnSync4 } from "child_process";
|
|
67463
67791
|
import {
|
|
67464
67792
|
closeSync as closeSync8,
|
|
67465
|
-
existsSync as
|
|
67466
|
-
mkdirSync as
|
|
67793
|
+
existsSync as existsSync32,
|
|
67794
|
+
mkdirSync as mkdirSync20,
|
|
67467
67795
|
openSync as openSync8,
|
|
67468
|
-
readFileSync as
|
|
67796
|
+
readFileSync as readFileSync32,
|
|
67469
67797
|
readdirSync as readdirSync8,
|
|
67470
67798
|
statSync as statSync8,
|
|
67471
67799
|
unlinkSync as unlinkSync9,
|
|
67472
|
-
writeFileSync as
|
|
67800
|
+
writeFileSync as writeFileSync21
|
|
67473
67801
|
} from "fs";
|
|
67474
|
-
import { homedir as
|
|
67475
|
-
import { dirname as
|
|
67802
|
+
import { homedir as homedir37, tmpdir as tmpdir2 } from "os";
|
|
67803
|
+
import { dirname as dirname14, join as join42 } from "path";
|
|
67476
67804
|
import { isatty } from "tty";
|
|
67477
67805
|
function releaseTerminalIsolation() {
|
|
67478
67806
|
if (!restoreTerminal)
|
|
@@ -67532,12 +67860,12 @@ function isRealAnthropicEnvCredential(env, name) {
|
|
|
67532
67860
|
}
|
|
67533
67861
|
function hasResolvableAnthropicAuth(deps = {}) {
|
|
67534
67862
|
const env = deps.env ?? process.env;
|
|
67535
|
-
const fileExists = deps.fileExists ??
|
|
67863
|
+
const fileExists = deps.fileExists ?? existsSync32;
|
|
67536
67864
|
const keychainProbe = deps.keychainProbe ?? defaultKeychainAnthropicProbe;
|
|
67537
67865
|
if (isRealAnthropicEnvCredential(env, "ANTHROPIC_API_KEY") || isRealAnthropicEnvCredential(env, "ANTHROPIC_AUTH_TOKEN")) {
|
|
67538
67866
|
return true;
|
|
67539
67867
|
}
|
|
67540
|
-
if (fileExists(
|
|
67868
|
+
if (fileExists(join42(homedir37(), ".claude", ".credentials.json")))
|
|
67541
67869
|
return true;
|
|
67542
67870
|
return keychainProbe();
|
|
67543
67871
|
}
|
|
@@ -67552,14 +67880,14 @@ function isProxyAuthMode(config) {
|
|
|
67552
67880
|
}
|
|
67553
67881
|
function managedSettingsPath() {
|
|
67554
67882
|
if (isWindows2()) {
|
|
67555
|
-
return
|
|
67883
|
+
return join42(process.env.PROGRAMDATA || "C:\\ProgramData", "ClaudeCode", "managed-settings.json");
|
|
67556
67884
|
}
|
|
67557
67885
|
if (process.platform === "darwin") {
|
|
67558
67886
|
return "/Library/Application Support/ClaudeCode/managed-settings.json";
|
|
67559
67887
|
}
|
|
67560
67888
|
return "/etc/claude-code/managed-settings.json";
|
|
67561
67889
|
}
|
|
67562
|
-
function managedSettingsForcesClaudeAi(readFile =
|
|
67890
|
+
function managedSettingsForcesClaudeAi(readFile = readFileSync32) {
|
|
67563
67891
|
try {
|
|
67564
67892
|
const raw = readFile(managedSettingsPath(), "utf-8");
|
|
67565
67893
|
const parsed = JSON.parse(raw);
|
|
@@ -67573,9 +67901,9 @@ function isWindows2() {
|
|
|
67573
67901
|
}
|
|
67574
67902
|
function createStatusLineScript(tokenFilePath) {
|
|
67575
67903
|
const homeDir = process.env.HOME || process.env.USERPROFILE || tmpdir2();
|
|
67576
|
-
const claudishDir =
|
|
67904
|
+
const claudishDir = join42(homeDir, ".claudish");
|
|
67577
67905
|
const timestamp = Date.now();
|
|
67578
|
-
const scriptPath =
|
|
67906
|
+
const scriptPath = join42(claudishDir, `status-${timestamp}.js`);
|
|
67579
67907
|
const escapedTokenPath = tokenFilePath.replace(/\\/g, "\\\\");
|
|
67580
67908
|
const light = getThemeMode() === "light";
|
|
67581
67909
|
const cyanCode = light ? "38;2;14;116;144" : "96";
|
|
@@ -67708,13 +68036,13 @@ process.stdin.on('end', () => {
|
|
|
67708
68036
|
}
|
|
67709
68037
|
});
|
|
67710
68038
|
`;
|
|
67711
|
-
|
|
68039
|
+
writeFileSync21(scriptPath, script, "utf-8");
|
|
67712
68040
|
return scriptPath;
|
|
67713
68041
|
}
|
|
67714
68042
|
function initializeTokenFile(tokenFilePath) {
|
|
67715
68043
|
try {
|
|
67716
|
-
|
|
67717
|
-
|
|
68044
|
+
mkdirSync20(dirname14(tokenFilePath), { recursive: true });
|
|
68045
|
+
writeFileSync21(tokenFilePath, JSON.stringify({
|
|
67718
68046
|
input_tokens: 0,
|
|
67719
68047
|
output_tokens: 0,
|
|
67720
68048
|
total_tokens: 0,
|
|
@@ -67745,7 +68073,7 @@ function cleanupStaleTokenFiles(dir, now = Date.now(), maxAgeMs = STALE_TOKEN_FI
|
|
|
67745
68073
|
if (!name.startsWith("tokens-") || !name.endsWith(".json"))
|
|
67746
68074
|
continue;
|
|
67747
68075
|
scanned++;
|
|
67748
|
-
const full =
|
|
68076
|
+
const full = join42(dir, name);
|
|
67749
68077
|
try {
|
|
67750
68078
|
if (statSync8(full).mtimeMs >= cutoff)
|
|
67751
68079
|
continue;
|
|
@@ -67762,7 +68090,7 @@ function parseSettingsArg(value) {
|
|
|
67762
68090
|
if (value.trimStart().startsWith("{")) {
|
|
67763
68091
|
return JSON.parse(value);
|
|
67764
68092
|
}
|
|
67765
|
-
return JSON.parse(
|
|
68093
|
+
return JSON.parse(readFileSync32(value, "utf-8"));
|
|
67766
68094
|
}
|
|
67767
68095
|
function parseSettingsArgSafe(value) {
|
|
67768
68096
|
try {
|
|
@@ -67774,13 +68102,13 @@ function parseSettingsArgSafe(value) {
|
|
|
67774
68102
|
}
|
|
67775
68103
|
function userSettingsFileCandidates(cwd) {
|
|
67776
68104
|
return [
|
|
67777
|
-
|
|
67778
|
-
|
|
67779
|
-
|
|
68105
|
+
join42(homedir37(), ".claude", "settings.json"),
|
|
68106
|
+
join42(cwd, ".claude", "settings.json"),
|
|
68107
|
+
join42(cwd, ".claude", "settings.local.json")
|
|
67780
68108
|
];
|
|
67781
68109
|
}
|
|
67782
68110
|
function discoverUserStatusLineCommand(claudeArgs = [], cwd = process.cwd()) {
|
|
67783
|
-
const sources = userSettingsFileCandidates(cwd).filter((file) =>
|
|
68111
|
+
const sources = userSettingsFileCandidates(cwd).filter((file) => existsSync32(file));
|
|
67784
68112
|
const idx = claudeArgs.indexOf("--settings");
|
|
67785
68113
|
const settingsArg = idx === -1 ? undefined : claudeArgs[idx + 1];
|
|
67786
68114
|
if (settingsArg)
|
|
@@ -67817,13 +68145,13 @@ function buildChainedStatusCommand(userCommand, claudishBody, claudishSegment) {
|
|
|
67817
68145
|
}
|
|
67818
68146
|
function createTempSettingsFile(_modelDisplay, port, proxyAuthMode, userStatusLineCommand) {
|
|
67819
68147
|
const homeDir = process.env.HOME || process.env.USERPROFILE || tmpdir2();
|
|
67820
|
-
const claudishDir =
|
|
68148
|
+
const claudishDir = join42(homeDir, ".claudish");
|
|
67821
68149
|
try {
|
|
67822
|
-
|
|
68150
|
+
mkdirSync20(claudishDir, { recursive: true });
|
|
67823
68151
|
} catch {}
|
|
67824
68152
|
const timestamp = Date.now();
|
|
67825
|
-
const tempPath =
|
|
67826
|
-
const tokenFilePath =
|
|
68153
|
+
const tempPath = join42(claudishDir, `settings-${timestamp}.json`);
|
|
68154
|
+
const tokenFilePath = join42(claudishDir, `tokens-${port}.json`);
|
|
67827
68155
|
cleanupStaleTokenFiles(claudishDir);
|
|
67828
68156
|
initializeTokenFile(tokenFilePath);
|
|
67829
68157
|
let statusCommand;
|
|
@@ -67857,7 +68185,7 @@ function createTempSettingsFile(_modelDisplay, port, proxyAuthMode, userStatusLi
|
|
|
67857
68185
|
padding: 0
|
|
67858
68186
|
};
|
|
67859
68187
|
const settings = buildClaudishSettingsOverlay(statusLine, proxyAuthMode);
|
|
67860
|
-
|
|
68188
|
+
writeFileSync21(tempPath, JSON.stringify(settings, null, 2), "utf-8");
|
|
67861
68189
|
return { path: tempPath, statusLine, tokenFilePath };
|
|
67862
68190
|
}
|
|
67863
68191
|
function buildClaudishSettingsOverlay(statusLine, proxyAuthMode) {
|
|
@@ -67882,7 +68210,7 @@ function mergeUserSettingsIfPresent(config, tempSettingsPath, statusLine, proxyA
|
|
|
67882
68210
|
if (proxyAuthMode && !("forceLoginMethod" in userSettings)) {
|
|
67883
68211
|
userSettings.forceLoginMethod = "console";
|
|
67884
68212
|
}
|
|
67885
|
-
|
|
68213
|
+
writeFileSync21(tempSettingsPath, JSON.stringify(userSettings, null, 2), "utf-8");
|
|
67886
68214
|
} catch {
|
|
67887
68215
|
if (!config.quiet) {
|
|
67888
68216
|
console.warn(`[claudish] Warning: could not merge user settings: ${userSettingsValue}`);
|
|
@@ -67953,13 +68281,13 @@ function resolveAdvisorToolEnv(config, processEnv = process.env) {
|
|
|
67953
68281
|
return { vars: { [ADVISOR_TOOL_ENV_VAR]: "1" }, source: "claudish" };
|
|
67954
68282
|
}
|
|
67955
68283
|
function discoverUserAdvisorModel(claudeArgs = [], cwd = process.cwd()) {
|
|
67956
|
-
const sources = userSettingsFileCandidates(cwd).filter((file) =>
|
|
68284
|
+
const sources = userSettingsFileCandidates(cwd).filter((file) => existsSync32(file));
|
|
67957
68285
|
const idx = claudeArgs.indexOf("--settings");
|
|
67958
68286
|
const settingsArg = idx === -1 ? undefined : claudeArgs[idx + 1];
|
|
67959
68287
|
if (settingsArg)
|
|
67960
68288
|
sources.push(settingsArg);
|
|
67961
68289
|
const managed = managedSettingsPath();
|
|
67962
|
-
if (
|
|
68290
|
+
if (existsSync32(managed))
|
|
67963
68291
|
sources.push(managed);
|
|
67964
68292
|
let effective;
|
|
67965
68293
|
for (const source of sources) {
|
|
@@ -68173,8 +68501,8 @@ async function runClaudeWithProxy(config, proxyUrl, onCleanup) {
|
|
|
68173
68501
|
console.error("Install it from: https://claude.com/claude-code");
|
|
68174
68502
|
console.error(`
|
|
68175
68503
|
Or set CLAUDE_PATH to your custom installation:`);
|
|
68176
|
-
const home =
|
|
68177
|
-
const localPath = isWindows2() ?
|
|
68504
|
+
const home = homedir37();
|
|
68505
|
+
const localPath = isWindows2() ? join42(home, ".claude", "local", "claude.exe") : join42(home, ".claude", "local", "claude");
|
|
68178
68506
|
console.error(` export CLAUDE_PATH=${localPath}`);
|
|
68179
68507
|
process.exit(1);
|
|
68180
68508
|
}
|
|
@@ -68262,23 +68590,23 @@ function setupSignalHandlers(proc, tempSettingsPath, quiet, onCleanup) {
|
|
|
68262
68590
|
async function findClaudeBinary() {
|
|
68263
68591
|
const isWindows = process.platform === "win32";
|
|
68264
68592
|
if (process.env.CLAUDE_PATH) {
|
|
68265
|
-
if (
|
|
68593
|
+
if (existsSync32(process.env.CLAUDE_PATH)) {
|
|
68266
68594
|
return process.env.CLAUDE_PATH;
|
|
68267
68595
|
}
|
|
68268
68596
|
}
|
|
68269
|
-
const home =
|
|
68270
|
-
const localPath = isWindows ?
|
|
68271
|
-
if (
|
|
68597
|
+
const home = homedir37();
|
|
68598
|
+
const localPath = isWindows ? join42(home, ".claude", "local", "claude.exe") : join42(home, ".claude", "local", "claude");
|
|
68599
|
+
if (existsSync32(localPath)) {
|
|
68272
68600
|
return localPath;
|
|
68273
68601
|
}
|
|
68274
68602
|
if (isWindows) {
|
|
68275
68603
|
const windowsPaths = [
|
|
68276
|
-
|
|
68277
|
-
|
|
68278
|
-
|
|
68604
|
+
join42(home, "AppData", "Roaming", "npm", "claude.cmd"),
|
|
68605
|
+
join42(home, ".npm-global", "claude.cmd"),
|
|
68606
|
+
join42(home, "node_modules", ".bin", "claude.cmd")
|
|
68279
68607
|
];
|
|
68280
68608
|
for (const path of windowsPaths) {
|
|
68281
|
-
if (
|
|
68609
|
+
if (existsSync32(path)) {
|
|
68282
68610
|
return path;
|
|
68283
68611
|
}
|
|
68284
68612
|
}
|
|
@@ -68286,14 +68614,14 @@ async function findClaudeBinary() {
|
|
|
68286
68614
|
const commonPaths = [
|
|
68287
68615
|
"/usr/local/bin/claude",
|
|
68288
68616
|
"/opt/homebrew/bin/claude",
|
|
68289
|
-
|
|
68290
|
-
|
|
68291
|
-
|
|
68617
|
+
join42(home, ".npm-global/bin/claude"),
|
|
68618
|
+
join42(home, ".local/bin/claude"),
|
|
68619
|
+
join42(home, "node_modules/.bin/claude"),
|
|
68292
68620
|
"/data/data/com.termux/files/usr/bin/claude",
|
|
68293
|
-
|
|
68621
|
+
join42(home, "../usr/bin/claude")
|
|
68294
68622
|
];
|
|
68295
68623
|
for (const path of commonPaths) {
|
|
68296
|
-
if (
|
|
68624
|
+
if (existsSync32(path)) {
|
|
68297
68625
|
return path;
|
|
68298
68626
|
}
|
|
68299
68627
|
}
|
|
@@ -68368,18 +68696,18 @@ var init_claude_runner = __esm(() => {
|
|
|
68368
68696
|
});
|
|
68369
68697
|
|
|
68370
68698
|
// src/diag-output.ts
|
|
68371
|
-
import { createWriteStream as createWriteStream3, mkdirSync as
|
|
68372
|
-
import { homedir as
|
|
68373
|
-
import { join as
|
|
68699
|
+
import { createWriteStream as createWriteStream3, mkdirSync as mkdirSync21, unlinkSync as unlinkSync10, writeFileSync as writeFileSync22 } from "fs";
|
|
68700
|
+
import { homedir as homedir38 } from "os";
|
|
68701
|
+
import { join as join43 } from "path";
|
|
68374
68702
|
function getClaudishDir() {
|
|
68375
|
-
const dir =
|
|
68703
|
+
const dir = join43(homedir38(), ".claudish");
|
|
68376
68704
|
try {
|
|
68377
|
-
|
|
68705
|
+
mkdirSync21(dir, { recursive: true });
|
|
68378
68706
|
} catch {}
|
|
68379
68707
|
return dir;
|
|
68380
68708
|
}
|
|
68381
68709
|
function getDiagLogPath() {
|
|
68382
|
-
return
|
|
68710
|
+
return join43(getClaudishDir(), `diag-${process.pid}.log`);
|
|
68383
68711
|
}
|
|
68384
68712
|
|
|
68385
68713
|
class LogFileDiagOutput {
|
|
@@ -68388,7 +68716,7 @@ class LogFileDiagOutput {
|
|
|
68388
68716
|
constructor() {
|
|
68389
68717
|
this.logPath = getDiagLogPath();
|
|
68390
68718
|
try {
|
|
68391
|
-
|
|
68719
|
+
writeFileSync22(this.logPath, `--- claudish diag session ${new Date().toISOString()} ---
|
|
68392
68720
|
`);
|
|
68393
68721
|
} catch {}
|
|
68394
68722
|
this.stream = createWriteStream3(this.logPath, { flags: "a" });
|
|
@@ -68590,13 +68918,33 @@ async function warmCatalogIfNeeded(config, opts) {
|
|
|
68590
68918
|
}
|
|
68591
68919
|
return "ok";
|
|
68592
68920
|
}
|
|
68921
|
+
return reportUnusableCatalog(outcome, state, cache, now, config.quiet === true);
|
|
68922
|
+
}
|
|
68923
|
+
function reportUnusableCatalog(outcome, state, cache, now, quiet) {
|
|
68924
|
+
if (outcome.kind === "incompatible") {
|
|
68925
|
+
return reportIncompatibleCatalog(readCatalogIncompatibility() ?? {
|
|
68926
|
+
detectedAt: new Date().toISOString(),
|
|
68927
|
+
serverContractVersion: outcome.serverContractVersion
|
|
68928
|
+
});
|
|
68929
|
+
}
|
|
68593
68930
|
if (outcome.reason === "disabled") {
|
|
68594
|
-
if (!
|
|
68931
|
+
if (!quiet) {
|
|
68595
68932
|
process.stderr.write(` Catalog refresh disabled (CLAUDISH_DISABLE_CATALOG_WARM=1).
|
|
68596
68933
|
`);
|
|
68597
68934
|
}
|
|
68598
68935
|
return "skipped";
|
|
68599
68936
|
}
|
|
68937
|
+
const recorded = readCatalogIncompatibility();
|
|
68938
|
+
if (recorded !== null)
|
|
68939
|
+
return reportIncompatibleCatalog(recorded);
|
|
68940
|
+
return reportFetchFailure(state, cache, now);
|
|
68941
|
+
}
|
|
68942
|
+
function reportIncompatibleCatalog(recorded) {
|
|
68943
|
+
process.stderr.write(`${catalogIncompatibilityMessage(recorded)}
|
|
68944
|
+
`);
|
|
68945
|
+
return "warned";
|
|
68946
|
+
}
|
|
68947
|
+
function reportFetchFailure(state, cache, now) {
|
|
68600
68948
|
if (state === "stale") {
|
|
68601
68949
|
const ageMs = now.getTime() - Date.parse(cache.lastUpdated);
|
|
68602
68950
|
const ageStr = humanizeAge(ageMs);
|
|
@@ -68618,6 +68966,7 @@ var HARD_FAIL_MESSAGE, LOCAL_MODEL_PREFIXES;
|
|
|
68618
68966
|
var init_catalog_warm = __esm(() => {
|
|
68619
68967
|
init_all_models_cache();
|
|
68620
68968
|
init_catalog_client();
|
|
68969
|
+
init_catalog_compatibility();
|
|
68621
68970
|
HARD_FAIL_MESSAGE = `Error: cannot reach model catalog and no cached copy found.
|
|
68622
68971
|
` + `
|
|
68623
68972
|
` + `To proceed:
|
|
@@ -70984,16 +71333,16 @@ var exports_session_stats = {};
|
|
|
70984
71333
|
__export(exports_session_stats, {
|
|
70985
71334
|
readSessionStats: () => readSessionStats
|
|
70986
71335
|
});
|
|
70987
|
-
import { readFileSync as
|
|
70988
|
-
import { homedir as
|
|
70989
|
-
import { join as
|
|
71336
|
+
import { readFileSync as readFileSync33 } from "fs";
|
|
71337
|
+
import { homedir as homedir39 } from "os";
|
|
71338
|
+
import { join as join44 } from "path";
|
|
70990
71339
|
function tokenFilePath(port) {
|
|
70991
|
-
return process.env.CLAUDISH_TOKEN_FILE ||
|
|
71340
|
+
return process.env.CLAUDISH_TOKEN_FILE || join44(homedir39(), ".claudish", `tokens-${port}.json`);
|
|
70992
71341
|
}
|
|
70993
71342
|
function readSessionStats(port, opts) {
|
|
70994
71343
|
let raw;
|
|
70995
71344
|
try {
|
|
70996
|
-
raw = JSON.parse(
|
|
71345
|
+
raw = JSON.parse(readFileSync33(tokenFilePath(port), "utf-8"));
|
|
70997
71346
|
} catch {
|
|
70998
71347
|
return null;
|
|
70999
71348
|
}
|
|
@@ -71350,8 +71699,8 @@ var init_session_summary = __esm(() => {
|
|
|
71350
71699
|
init_op_source();
|
|
71351
71700
|
init_startup_trace();
|
|
71352
71701
|
var import_dotenv3 = __toESM(require_main(), 1);
|
|
71353
|
-
import { existsSync as
|
|
71354
|
-
import { join as
|
|
71702
|
+
import { existsSync as existsSync33, readFileSync as readFileSync34 } from "fs";
|
|
71703
|
+
import { join as join45, resolve as resolve6 } from "path";
|
|
71355
71704
|
import_dotenv3.config({ quiet: true });
|
|
71356
71705
|
function classifyStartupKind() {
|
|
71357
71706
|
const argv = process.argv.slice(2);
|
|
@@ -71451,7 +71800,7 @@ async function applyConfigOverride() {
|
|
|
71451
71800
|
await Promise.resolve();
|
|
71452
71801
|
const plan = planConfigOverride(process.argv.slice(2), process.env, {
|
|
71453
71802
|
resolve: resolve6,
|
|
71454
|
-
exists:
|
|
71803
|
+
exists: existsSync33
|
|
71455
71804
|
});
|
|
71456
71805
|
if (plan.kind === "none")
|
|
71457
71806
|
return;
|
|
@@ -71620,14 +71969,14 @@ async function runCli() {
|
|
|
71620
71969
|
if (cliConfig.team && cliConfig.team.length > 0) {
|
|
71621
71970
|
let prompt = cliConfig.claudeArgs.join(" ");
|
|
71622
71971
|
if (cliConfig.inputFile) {
|
|
71623
|
-
prompt =
|
|
71972
|
+
prompt = readFileSync34(cliConfig.inputFile, "utf-8");
|
|
71624
71973
|
}
|
|
71625
71974
|
if (!prompt.trim()) {
|
|
71626
71975
|
console.error("Error: --team requires a prompt (positional args or -f <file>)");
|
|
71627
71976
|
process.exit(1);
|
|
71628
71977
|
}
|
|
71629
71978
|
const mode = cliConfig.teamMode ?? "default";
|
|
71630
|
-
const sessionPath =
|
|
71979
|
+
const sessionPath = join45(process.cwd(), `.claudish-team-${Date.now()}`);
|
|
71631
71980
|
if (mode === "json") {
|
|
71632
71981
|
await Promise.resolve().then(() => init_team_orchestrator());
|
|
71633
71982
|
setupSession(sessionPath, cliConfig.team, prompt);
|
|
@@ -71636,9 +71985,9 @@ async function runCli() {
|
|
|
71636
71985
|
});
|
|
71637
71986
|
const result = { ...status, responses: {} };
|
|
71638
71987
|
for (const anonId of Object.keys(status.models)) {
|
|
71639
|
-
const responsePath =
|
|
71988
|
+
const responsePath = join45(sessionPath, `response-${anonId}.md`);
|
|
71640
71989
|
try {
|
|
71641
|
-
const raw =
|
|
71990
|
+
const raw = readFileSync34(responsePath, "utf-8").trim();
|
|
71642
71991
|
try {
|
|
71643
71992
|
result.responses[anonId] = JSON.parse(raw);
|
|
71644
71993
|
} catch {
|