@polka-codes/cli-shared 0.9.101 → 0.9.102
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 +277 -73
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16517,7 +16517,7 @@ var require_gaxios = __commonJS((exports) => {
|
|
|
16517
16517
|
var retry_js_1 = require_retry();
|
|
16518
16518
|
var stream_1 = __require("stream");
|
|
16519
16519
|
var interceptor_js_1 = require_interceptor();
|
|
16520
|
-
var
|
|
16520
|
+
var randomUUID2 = async () => globalThis.crypto?.randomUUID() || (await import("crypto")).randomUUID();
|
|
16521
16521
|
var HTTP_STATUS_NO_CONTENT = 204;
|
|
16522
16522
|
|
|
16523
16523
|
class Gaxios {
|
|
@@ -16607,8 +16607,8 @@ var require_gaxios = __commonJS((exports) => {
|
|
|
16607
16607
|
} else {
|
|
16608
16608
|
err = new common_js_1.GaxiosError("Unexpected Gaxios Error", opts, undefined, e2);
|
|
16609
16609
|
}
|
|
16610
|
-
const { shouldRetry, config: config3 } = await (0, retry_js_1.getRetryConfig)(err);
|
|
16611
|
-
if (
|
|
16610
|
+
const { shouldRetry: shouldRetry2, config: config3 } = await (0, retry_js_1.getRetryConfig)(err);
|
|
16611
|
+
if (shouldRetry2 && config3) {
|
|
16612
16612
|
err.config.retryConfig.currentRetryAttempt = config3.retryConfig.currentRetryAttempt;
|
|
16613
16613
|
opts.retryConfig = err.config?.retryConfig;
|
|
16614
16614
|
this.#appendTimeoutToSignal(opts);
|
|
@@ -16728,7 +16728,7 @@ var require_gaxios = __commonJS((exports) => {
|
|
|
16728
16728
|
}
|
|
16729
16729
|
const shouldDirectlyPassData = typeof opts.data === "string" || opts.data instanceof ArrayBuffer || opts.data instanceof Blob || globalThis.File && opts.data instanceof File || opts.data instanceof FormData || opts.data instanceof stream_1.Readable || opts.data instanceof ReadableStream || opts.data instanceof String || opts.data instanceof URLSearchParams || ArrayBuffer.isView(opts.data) || ["Blob", "File", "FormData"].includes(opts.data?.constructor?.name || "");
|
|
16730
16730
|
if (opts.multipart?.length) {
|
|
16731
|
-
const boundary = await
|
|
16731
|
+
const boundary = await randomUUID2();
|
|
16732
16732
|
preparedHeaders.set("content-type", `multipart/related; boundary=${boundary}`);
|
|
16733
16733
|
opts.body = stream_1.Readable.from(this.getMultipartRequest(opts.multipart, boundary));
|
|
16734
16734
|
} else if (shouldDirectlyPassData) {
|
|
@@ -21868,7 +21868,7 @@ var require_src6 = __commonJS((exports) => {
|
|
|
21868
21868
|
});
|
|
21869
21869
|
};
|
|
21870
21870
|
}
|
|
21871
|
-
var
|
|
21871
|
+
var readFile3 = fs3.readFile ? (0, _util.promisify)(fs3.readFile) : /* @__PURE__ */ _asyncToGenerator(/* @__PURE__ */ _regenerator().m(function _callee() {
|
|
21872
21872
|
return _regenerator().w(function(_context) {
|
|
21873
21873
|
while (true)
|
|
21874
21874
|
switch (_context.n) {
|
|
@@ -21995,7 +21995,7 @@ var require_src6 = __commonJS((exports) => {
|
|
|
21995
21995
|
break;
|
|
21996
21996
|
case 1:
|
|
21997
21997
|
_context2.n = 2;
|
|
21998
|
-
return
|
|
21998
|
+
return readFile3(keyFile, "utf8");
|
|
21999
21999
|
case 2:
|
|
22000
22000
|
key = _context2.v;
|
|
22001
22001
|
body = JSON.parse(key);
|
|
@@ -22013,7 +22013,7 @@ var require_src6 = __commonJS((exports) => {
|
|
|
22013
22013
|
});
|
|
22014
22014
|
case 4:
|
|
22015
22015
|
_context2.n = 5;
|
|
22016
|
-
return
|
|
22016
|
+
return readFile3(keyFile, "utf8");
|
|
22017
22017
|
case 5:
|
|
22018
22018
|
_privateKey = _context2.v;
|
|
22019
22019
|
return _context2.a(2, {
|
|
@@ -23251,7 +23251,7 @@ var require_filesubjecttokensupplier = __commonJS((exports) => {
|
|
|
23251
23251
|
exports.FileSubjectTokenSupplier = undefined;
|
|
23252
23252
|
var util_1 = __require("util");
|
|
23253
23253
|
var fs3 = __require("fs");
|
|
23254
|
-
var
|
|
23254
|
+
var readFile3 = (0, util_1.promisify)(fs3.readFile ?? (() => {}));
|
|
23255
23255
|
var realpath = (0, util_1.promisify)(fs3.realpath ?? (() => {}));
|
|
23256
23256
|
var lstat = (0, util_1.promisify)(fs3.lstat ?? (() => {}));
|
|
23257
23257
|
|
|
@@ -23278,7 +23278,7 @@ var require_filesubjecttokensupplier = __commonJS((exports) => {
|
|
|
23278
23278
|
throw err;
|
|
23279
23279
|
}
|
|
23280
23280
|
let subjectToken;
|
|
23281
|
-
const rawText = await
|
|
23281
|
+
const rawText = await readFile3(parsedFilePath, { encoding: "utf8" });
|
|
23282
23282
|
if (this.formatType === "text") {
|
|
23283
23283
|
subjectToken = rawText;
|
|
23284
23284
|
} else if (this.formatType === "json" && this.subjectTokenFieldName) {
|
|
@@ -37390,9 +37390,9 @@ var require_sql_wasm = __commonJS((exports, module) => {
|
|
|
37390
37390
|
|
|
37391
37391
|
// src/config.ts
|
|
37392
37392
|
import { existsSync, readFileSync } from "node:fs";
|
|
37393
|
-
import { readFile } from "node:fs/promises";
|
|
37394
|
-
import { homedir } from "node:os";
|
|
37395
|
-
import { join } from "node:path";
|
|
37393
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
37394
|
+
import { homedir as homedir2 } from "node:os";
|
|
37395
|
+
import { join as join2 } from "node:path";
|
|
37396
37396
|
// ../../node_modules/zod/v4/classic/external.js
|
|
37397
37397
|
var exports_external = {};
|
|
37398
37398
|
__export(exports_external, {
|
|
@@ -51102,6 +51102,179 @@ var configSchema = exports_external.object({
|
|
|
51102
51102
|
memory: memoryConfigSchema,
|
|
51103
51103
|
loadRules: exports_external.record(exports_external.string(), exports_external.boolean()).optional()
|
|
51104
51104
|
}).strict().nullish();
|
|
51105
|
+
// ../core/src/pricing/pricing-service.ts
|
|
51106
|
+
import { randomUUID } from "node:crypto";
|
|
51107
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
51108
|
+
import { homedir } from "node:os";
|
|
51109
|
+
import { dirname, join } from "node:path";
|
|
51110
|
+
|
|
51111
|
+
// ../core/src/pricing/converter.ts
|
|
51112
|
+
function convertPortkeyToModelInfo(portkey) {
|
|
51113
|
+
return {
|
|
51114
|
+
inputPrice: (portkey.request_token?.price ?? 0) * 10,
|
|
51115
|
+
outputPrice: (portkey.response_token?.price ?? 0) * 10,
|
|
51116
|
+
cacheWritesPrice: (portkey.cache_write_input_token?.price ?? 0) * 10,
|
|
51117
|
+
cacheReadsPrice: (portkey.cache_read_input_token?.price ?? 0) * 10
|
|
51118
|
+
};
|
|
51119
|
+
}
|
|
51120
|
+
|
|
51121
|
+
// ../core/src/pricing/portkey-client.ts
|
|
51122
|
+
var PORTKEY_BASE_URL = "https://api.portkey.ai/model-configs/pricing";
|
|
51123
|
+
var TIMEOUT_MS = 5000;
|
|
51124
|
+
var MAX_RETRIES = 2;
|
|
51125
|
+
async function fetchWithTimeout(url2, timeoutMs) {
|
|
51126
|
+
const controller = new AbortController;
|
|
51127
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
51128
|
+
try {
|
|
51129
|
+
const response = await fetch(url2, { signal: controller.signal });
|
|
51130
|
+
return response;
|
|
51131
|
+
} finally {
|
|
51132
|
+
clearTimeout(timeout);
|
|
51133
|
+
}
|
|
51134
|
+
}
|
|
51135
|
+
async function sleep(ms) {
|
|
51136
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
51137
|
+
}
|
|
51138
|
+
function shouldRetry(response, error48) {
|
|
51139
|
+
if (error48)
|
|
51140
|
+
return true;
|
|
51141
|
+
if (response.status >= 500)
|
|
51142
|
+
return true;
|
|
51143
|
+
return false;
|
|
51144
|
+
}
|
|
51145
|
+
async function fetchPricing(provider, model) {
|
|
51146
|
+
const url2 = `${PORTKEY_BASE_URL}/${provider}/${model}`;
|
|
51147
|
+
for (let attempt = 0;attempt <= MAX_RETRIES; attempt++) {
|
|
51148
|
+
try {
|
|
51149
|
+
const response = await fetchWithTimeout(url2, TIMEOUT_MS);
|
|
51150
|
+
if (!response.ok) {
|
|
51151
|
+
if (!shouldRetry(response, null)) {
|
|
51152
|
+
return null;
|
|
51153
|
+
}
|
|
51154
|
+
if (attempt < MAX_RETRIES) {
|
|
51155
|
+
await sleep(2 ** attempt * 1000);
|
|
51156
|
+
continue;
|
|
51157
|
+
}
|
|
51158
|
+
return null;
|
|
51159
|
+
}
|
|
51160
|
+
const data = await response.json();
|
|
51161
|
+
return data;
|
|
51162
|
+
} catch (error48) {
|
|
51163
|
+
if (attempt < MAX_RETRIES && shouldRetry(new Response(null, { status: 500 }), error48)) {
|
|
51164
|
+
await sleep(2 ** attempt * 1000);
|
|
51165
|
+
continue;
|
|
51166
|
+
}
|
|
51167
|
+
return null;
|
|
51168
|
+
}
|
|
51169
|
+
}
|
|
51170
|
+
return null;
|
|
51171
|
+
}
|
|
51172
|
+
|
|
51173
|
+
// ../core/src/pricing/pricing-service.ts
|
|
51174
|
+
var CACHE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
51175
|
+
|
|
51176
|
+
class PricingService {
|
|
51177
|
+
#fallbackPrices;
|
|
51178
|
+
#cacheFile;
|
|
51179
|
+
#cache = null;
|
|
51180
|
+
#loadPromise = null;
|
|
51181
|
+
constructor(fallbackPrices = {}) {
|
|
51182
|
+
const normalized = {};
|
|
51183
|
+
for (const [provider, providerInfo] of Object.entries(fallbackPrices)) {
|
|
51184
|
+
const normalizedProvider = provider.split("-")[0];
|
|
51185
|
+
normalized[normalizedProvider] = {};
|
|
51186
|
+
for (const [model, modelInfo] of Object.entries(providerInfo)) {
|
|
51187
|
+
const normalizedModel = model.replace(/[.-]/g, "");
|
|
51188
|
+
normalized[normalizedProvider][normalizedModel] = {
|
|
51189
|
+
inputPrice: modelInfo.inputPrice ?? 0,
|
|
51190
|
+
outputPrice: modelInfo.outputPrice ?? 0,
|
|
51191
|
+
cacheWritesPrice: modelInfo.cacheWritesPrice ?? 0,
|
|
51192
|
+
cacheReadsPrice: modelInfo.cacheReadsPrice ?? 0
|
|
51193
|
+
};
|
|
51194
|
+
}
|
|
51195
|
+
}
|
|
51196
|
+
this.#fallbackPrices = normalized;
|
|
51197
|
+
this.#cacheFile = join(homedir(), ".config", "polkacodes", "pricing-cache.json");
|
|
51198
|
+
}
|
|
51199
|
+
async#load() {
|
|
51200
|
+
if (this.#loadPromise) {
|
|
51201
|
+
return this.#loadPromise;
|
|
51202
|
+
}
|
|
51203
|
+
this.#loadPromise = (async () => {
|
|
51204
|
+
this.#cache = new Map;
|
|
51205
|
+
try {
|
|
51206
|
+
const content = await readFile(this.#cacheFile, "utf-8");
|
|
51207
|
+
const data = JSON.parse(content);
|
|
51208
|
+
for (const [key, value] of Object.entries(data)) {
|
|
51209
|
+
this.#cache.set(key, value);
|
|
51210
|
+
}
|
|
51211
|
+
} catch {}
|
|
51212
|
+
})();
|
|
51213
|
+
return this.#loadPromise;
|
|
51214
|
+
}
|
|
51215
|
+
async#get(provider, model) {
|
|
51216
|
+
await this.#load();
|
|
51217
|
+
const key = `${provider}:${model}`;
|
|
51218
|
+
const entry = this.#cache?.get(key);
|
|
51219
|
+
if (!entry) {
|
|
51220
|
+
return null;
|
|
51221
|
+
}
|
|
51222
|
+
if (Date.now() - entry.timestamp > CACHE_TTL_MS) {
|
|
51223
|
+
this.#cache?.delete(key);
|
|
51224
|
+
return null;
|
|
51225
|
+
}
|
|
51226
|
+
return entry.pricing;
|
|
51227
|
+
}
|
|
51228
|
+
async#set(provider, model, pricing) {
|
|
51229
|
+
await this.#load();
|
|
51230
|
+
const key = `${provider}:${model}`;
|
|
51231
|
+
this.#cache?.set(key, {
|
|
51232
|
+
pricing,
|
|
51233
|
+
timestamp: Date.now()
|
|
51234
|
+
});
|
|
51235
|
+
await this.#save();
|
|
51236
|
+
}
|
|
51237
|
+
async#save() {
|
|
51238
|
+
if (!this.#cache) {
|
|
51239
|
+
return;
|
|
51240
|
+
}
|
|
51241
|
+
try {
|
|
51242
|
+
const dir = dirname(this.#cacheFile);
|
|
51243
|
+
await mkdir(dir, { recursive: true });
|
|
51244
|
+
const data = {};
|
|
51245
|
+
for (const [key, value] of this.#cache.entries()) {
|
|
51246
|
+
data[key] = value;
|
|
51247
|
+
}
|
|
51248
|
+
const tempFile = `${this.#cacheFile}.${randomUUID()}.tmp`;
|
|
51249
|
+
await writeFile(tempFile, JSON.stringify(data, null, 2), "utf-8");
|
|
51250
|
+
await rename(tempFile, this.#cacheFile);
|
|
51251
|
+
} catch {}
|
|
51252
|
+
}
|
|
51253
|
+
async getPricing(provider, model) {
|
|
51254
|
+
const normalizedProvider = provider.split("-")[0];
|
|
51255
|
+
const normalizedModel = model.replace(/[.-]/g, "");
|
|
51256
|
+
const cached2 = await this.#get(normalizedProvider, normalizedModel);
|
|
51257
|
+
if (cached2) {
|
|
51258
|
+
return cached2;
|
|
51259
|
+
}
|
|
51260
|
+
const fallbackPrice = this.#fallbackPrices[normalizedProvider]?.[normalizedModel];
|
|
51261
|
+
if (fallbackPrice) {
|
|
51262
|
+
return fallbackPrice;
|
|
51263
|
+
}
|
|
51264
|
+
const portkeyPricing = await fetchPricing(normalizedProvider, model);
|
|
51265
|
+
if (portkeyPricing) {
|
|
51266
|
+
const modelInfo = convertPortkeyToModelInfo(portkeyPricing);
|
|
51267
|
+
await this.#set(normalizedProvider, normalizedModel, modelInfo);
|
|
51268
|
+
return modelInfo;
|
|
51269
|
+
}
|
|
51270
|
+
return {
|
|
51271
|
+
inputPrice: 0,
|
|
51272
|
+
outputPrice: 0,
|
|
51273
|
+
cacheWritesPrice: 0,
|
|
51274
|
+
cacheReadsPrice: 0
|
|
51275
|
+
};
|
|
51276
|
+
}
|
|
51277
|
+
}
|
|
51105
51278
|
// ../core/src/skills/constants.ts
|
|
51106
51279
|
var SKILL_LIMITS = {
|
|
51107
51280
|
MAX_FILE_SIZE: 1024 * 1024,
|
|
@@ -52335,9 +52508,11 @@ var writeToFile_default = {
|
|
|
52335
52508
|
class UsageMeter {
|
|
52336
52509
|
#totals = { input: 0, output: 0, cachedRead: 0, cost: 0, messageCount: 0 };
|
|
52337
52510
|
#providerMetadataEntries = [];
|
|
52511
|
+
#pendingUpdates = new Set;
|
|
52338
52512
|
#modelInfos;
|
|
52339
52513
|
#maxMessages;
|
|
52340
52514
|
#maxCost;
|
|
52515
|
+
#pricingService;
|
|
52341
52516
|
constructor(modelInfos = {}, opts = {}) {
|
|
52342
52517
|
const infos = {};
|
|
52343
52518
|
for (const [provider2, providerInfo] of Object.entries(modelInfos)) {
|
|
@@ -52353,6 +52528,7 @@ class UsageMeter {
|
|
|
52353
52528
|
this.#modelInfos = infos;
|
|
52354
52529
|
this.#maxMessages = opts.maxMessages ?? 1000;
|
|
52355
52530
|
this.#maxCost = opts.maxCost ?? 100;
|
|
52531
|
+
this.#pricingService = opts.pricingService;
|
|
52356
52532
|
}
|
|
52357
52533
|
#calculateUsage(usage, providerMetadata, modelInfo) {
|
|
52358
52534
|
const providerMetadataKey = Object.keys(providerMetadata ?? {})[0];
|
|
@@ -52403,28 +52579,52 @@ class UsageMeter {
|
|
|
52403
52579
|
}
|
|
52404
52580
|
}
|
|
52405
52581
|
addUsage(llm, resp, options = {}) {
|
|
52406
|
-
const
|
|
52407
|
-
|
|
52408
|
-
|
|
52409
|
-
|
|
52410
|
-
|
|
52411
|
-
|
|
52412
|
-
|
|
52413
|
-
|
|
52414
|
-
|
|
52415
|
-
|
|
52416
|
-
|
|
52417
|
-
|
|
52418
|
-
|
|
52419
|
-
|
|
52420
|
-
|
|
52421
|
-
|
|
52422
|
-
|
|
52423
|
-
|
|
52424
|
-
|
|
52425
|
-
|
|
52426
|
-
|
|
52427
|
-
|
|
52582
|
+
const provider2 = llm.provider.split(".")[0];
|
|
52583
|
+
const normalizedModel = llm.modelId.replace(/[.-]/g, "");
|
|
52584
|
+
const key = `${provider2}:${normalizedModel}`;
|
|
52585
|
+
let modelInfo = options.modelInfo ?? this.#modelInfos[key];
|
|
52586
|
+
const updatePromise = (async () => {
|
|
52587
|
+
try {
|
|
52588
|
+
if (!modelInfo && this.#pricingService) {
|
|
52589
|
+
modelInfo = await this.#pricingService.getPricing(provider2, llm.modelId);
|
|
52590
|
+
this.#modelInfos[key] = modelInfo;
|
|
52591
|
+
}
|
|
52592
|
+
} catch {
|
|
52593
|
+
modelInfo = {
|
|
52594
|
+
inputPrice: 0,
|
|
52595
|
+
outputPrice: 0,
|
|
52596
|
+
cacheWritesPrice: 0,
|
|
52597
|
+
cacheReadsPrice: 0
|
|
52598
|
+
};
|
|
52599
|
+
}
|
|
52600
|
+
modelInfo = modelInfo ?? {
|
|
52601
|
+
inputPrice: 0,
|
|
52602
|
+
outputPrice: 0,
|
|
52603
|
+
cacheWritesPrice: 0,
|
|
52604
|
+
cacheReadsPrice: 0
|
|
52605
|
+
};
|
|
52606
|
+
const usage = "totalUsage" in resp ? resp.totalUsage : resp.usage;
|
|
52607
|
+
const result = this.#calculateUsage(usage, resp.providerMetadata, modelInfo);
|
|
52608
|
+
this.#totals.input += result.input || 0;
|
|
52609
|
+
this.#totals.output += result.output || 0;
|
|
52610
|
+
this.#totals.cachedRead += result.cachedRead || 0;
|
|
52611
|
+
this.#totals.cost += result.cost || 0;
|
|
52612
|
+
this.#totals.messageCount += 1;
|
|
52613
|
+
if (resp.providerMetadata && Object.keys(resp.providerMetadata).length > 0) {
|
|
52614
|
+
const providerKey = Object.keys(resp.providerMetadata)[0];
|
|
52615
|
+
this.#providerMetadataEntries.push({
|
|
52616
|
+
provider: providerKey || llm.provider,
|
|
52617
|
+
model: llm.modelId,
|
|
52618
|
+
metadata: resp.providerMetadata[providerKey] || resp.providerMetadata,
|
|
52619
|
+
timestamp: Date.now()
|
|
52620
|
+
});
|
|
52621
|
+
}
|
|
52622
|
+
})();
|
|
52623
|
+
this.#pendingUpdates.add(updatePromise);
|
|
52624
|
+
updatePromise.finally(() => {
|
|
52625
|
+
this.#pendingUpdates.delete(updatePromise);
|
|
52626
|
+
});
|
|
52627
|
+
return updatePromise;
|
|
52428
52628
|
}
|
|
52429
52629
|
setUsage(newUsage, options = {}) {
|
|
52430
52630
|
if (newUsage.input != null)
|
|
@@ -52508,13 +52708,17 @@ class UsageMeter {
|
|
|
52508
52708
|
this.#totals.messageCount += otherUsage.messageCount;
|
|
52509
52709
|
this.#providerMetadataEntries.push(...other.providerMetadata);
|
|
52510
52710
|
}
|
|
52711
|
+
async waitForPending() {
|
|
52712
|
+
const pending = Array.from(this.#pendingUpdates);
|
|
52713
|
+
await Promise.allSettled(pending);
|
|
52714
|
+
}
|
|
52511
52715
|
getUsageText() {
|
|
52512
52716
|
const u = this.usage;
|
|
52513
52717
|
return `Usage - messages: ${u.messageCount}, input: ${u.input}, cached: ${u.cachedRead}, output: ${u.output}, cost: $${u.cost.toFixed(4)}`;
|
|
52514
52718
|
}
|
|
52515
52719
|
onFinishHandler(llm) {
|
|
52516
|
-
return (evt) => {
|
|
52517
|
-
this.addUsage(llm, evt);
|
|
52720
|
+
return async (evt) => {
|
|
52721
|
+
await this.addUsage(llm, evt);
|
|
52518
52722
|
};
|
|
52519
52723
|
}
|
|
52520
52724
|
}
|
|
@@ -63317,8 +63521,8 @@ var merge2 = _createAssigner_default(function(object3, source, srcIndex) {
|
|
|
63317
63521
|
});
|
|
63318
63522
|
var merge_default = merge2;
|
|
63319
63523
|
// src/config.ts
|
|
63320
|
-
function getGlobalConfigPath(home =
|
|
63321
|
-
return
|
|
63524
|
+
function getGlobalConfigPath(home = homedir2()) {
|
|
63525
|
+
return join2(home, ".config", "polkacodes", "config.yml");
|
|
63322
63526
|
}
|
|
63323
63527
|
function loadConfigAtPath(path) {
|
|
63324
63528
|
try {
|
|
@@ -63406,7 +63610,7 @@ async function resolveRules(rules) {
|
|
|
63406
63610
|
}
|
|
63407
63611
|
} else if ("path" in rule) {
|
|
63408
63612
|
if (existsSync(rule.path)) {
|
|
63409
|
-
return await
|
|
63613
|
+
return await readFile2(rule.path, "utf-8");
|
|
63410
63614
|
}
|
|
63411
63615
|
console.warn(`Rule file not found: ${rule.path}`);
|
|
63412
63616
|
}
|
|
@@ -63416,7 +63620,7 @@ async function resolveRules(rules) {
|
|
|
63416
63620
|
|
|
63417
63621
|
`);
|
|
63418
63622
|
}
|
|
63419
|
-
async function loadConfig(paths, cwd = process.cwd(), home =
|
|
63623
|
+
async function loadConfig(paths, cwd = process.cwd(), home = homedir2()) {
|
|
63420
63624
|
const configs = [];
|
|
63421
63625
|
const globalConfigPath = getGlobalConfigPath(home);
|
|
63422
63626
|
if (existsSync(globalConfigPath)) {
|
|
@@ -63445,7 +63649,7 @@ ${error48}`);
|
|
|
63445
63649
|
}
|
|
63446
63650
|
}
|
|
63447
63651
|
} else {
|
|
63448
|
-
const configPath =
|
|
63652
|
+
const configPath = join2(cwd, localConfigFileName);
|
|
63449
63653
|
try {
|
|
63450
63654
|
const projectConfig = readConfig(configPath);
|
|
63451
63655
|
configs.push(projectConfig);
|
|
@@ -63529,7 +63733,7 @@ class MemoryManager {
|
|
|
63529
63733
|
}
|
|
63530
63734
|
// src/project-scope.ts
|
|
63531
63735
|
import { existsSync as existsSync2 } from "node:fs";
|
|
63532
|
-
import { dirname, normalize, resolve as resolve2, sep } from "node:path";
|
|
63736
|
+
import { dirname as dirname2, normalize, resolve as resolve2, sep } from "node:path";
|
|
63533
63737
|
function detectProjectScope(cwd) {
|
|
63534
63738
|
const projectPath = findProjectRoot(cwd);
|
|
63535
63739
|
if (!projectPath) {
|
|
@@ -63563,7 +63767,7 @@ function findProjectRoot(dir) {
|
|
|
63563
63767
|
return dir;
|
|
63564
63768
|
}
|
|
63565
63769
|
}
|
|
63566
|
-
const parent =
|
|
63770
|
+
const parent = dirname2(dir);
|
|
63567
63771
|
if (parent === dir) {
|
|
63568
63772
|
return null;
|
|
63569
63773
|
}
|
|
@@ -63574,8 +63778,8 @@ function normalizePath(path) {
|
|
|
63574
63778
|
}
|
|
63575
63779
|
// src/provider.ts
|
|
63576
63780
|
import { spawn as spawn2 } from "node:child_process";
|
|
63577
|
-
import { mkdir, readFile as
|
|
63578
|
-
import { dirname as
|
|
63781
|
+
import { mkdir as mkdir2, readFile as readFile3, rename as rename2, unlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
63782
|
+
import { dirname as dirname3, normalize as normalize2, resolve as resolve4 } from "node:path";
|
|
63579
63783
|
|
|
63580
63784
|
// ../../node_modules/@ai-sdk/google-vertex/dist/index.mjs
|
|
63581
63785
|
var import_google_auth_library = __toESM(require_src7(), 1);
|
|
@@ -66991,7 +67195,7 @@ function checkRipgrep() {
|
|
|
66991
67195
|
// src/utils/listFiles.ts
|
|
66992
67196
|
var import_ignore = __toESM(require_ignore(), 1);
|
|
66993
67197
|
import { promises as fs3 } from "node:fs";
|
|
66994
|
-
import { join as
|
|
67198
|
+
import { join as join3, relative, resolve as resolve3 } from "node:path";
|
|
66995
67199
|
var DEFAULT_IGNORES = [
|
|
66996
67200
|
"__pycache__",
|
|
66997
67201
|
".DS_Store",
|
|
@@ -67009,7 +67213,7 @@ var DEFAULT_IGNORES = [
|
|
|
67009
67213
|
];
|
|
67010
67214
|
async function extendPatterns(basePatterns, dirPath) {
|
|
67011
67215
|
try {
|
|
67012
|
-
const gitignorePath =
|
|
67216
|
+
const gitignorePath = join3(dirPath, ".gitignore");
|
|
67013
67217
|
const content = await fs3.readFile(gitignorePath, "utf8");
|
|
67014
67218
|
const lines = content.split(/\r?\n/).filter(Boolean);
|
|
67015
67219
|
return [...basePatterns, ...lines];
|
|
@@ -67025,7 +67229,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
|
|
|
67025
67229
|
if (!includeIgnored) {
|
|
67026
67230
|
rootPatterns.push(...DEFAULT_IGNORES);
|
|
67027
67231
|
try {
|
|
67028
|
-
const rootGitignore = await fs3.readFile(
|
|
67232
|
+
const rootGitignore = await fs3.readFile(join3(cwd, ".gitignore"), "utf8");
|
|
67029
67233
|
const lines = rootGitignore.split(/\r?\n/).filter(Boolean);
|
|
67030
67234
|
rootPatterns = [...rootPatterns, ...lines];
|
|
67031
67235
|
} catch {}
|
|
@@ -67047,7 +67251,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
|
|
|
67047
67251
|
const entries = await fs3.readdir(currentPath, { withFileTypes: true });
|
|
67048
67252
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
67049
67253
|
for (const entry of entries) {
|
|
67050
|
-
const fullPath =
|
|
67254
|
+
const fullPath = join3(currentPath, entry.name);
|
|
67051
67255
|
const relPath = relative(cwd, fullPath).replace(/\\/g, "/");
|
|
67052
67256
|
if (folderIg.ignores(relPath)) {
|
|
67053
67257
|
continue;
|
|
@@ -67064,7 +67268,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
|
|
|
67064
67268
|
results.push(relPath);
|
|
67065
67269
|
if (results.length >= maxCount) {
|
|
67066
67270
|
const remainingEntries = entries.slice(entries.indexOf(entry) + 1);
|
|
67067
|
-
const hasRemainingFiles = remainingEntries.some((e2) => !e2.isDirectory() && !folderIg.ignores(relative(cwd,
|
|
67271
|
+
const hasRemainingFiles = remainingEntries.some((e2) => !e2.isDirectory() && !folderIg.ignores(relative(cwd, join3(currentPath, e2.name)).replace(/\\/g, "/")));
|
|
67068
67272
|
if (hasRemainingFiles) {
|
|
67069
67273
|
const marker16 = `${currentRelPath}/(files omitted)`;
|
|
67070
67274
|
results.push(marker16);
|
|
@@ -67316,7 +67520,7 @@ ${content}`;
|
|
|
67316
67520
|
throw new Error(`Not allow to access file ${path}`);
|
|
67317
67521
|
}
|
|
67318
67522
|
try {
|
|
67319
|
-
return await
|
|
67523
|
+
return await readFile3(path, "utf8");
|
|
67320
67524
|
} catch (_e) {
|
|
67321
67525
|
return;
|
|
67322
67526
|
}
|
|
@@ -67325,8 +67529,8 @@ ${content}`;
|
|
|
67325
67529
|
if (ig.ignores(path)) {
|
|
67326
67530
|
throw new Error(`Not allow to access file ${path}`);
|
|
67327
67531
|
}
|
|
67328
|
-
await
|
|
67329
|
-
return await
|
|
67532
|
+
await mkdir2(dirname3(path), { recursive: true });
|
|
67533
|
+
return await writeFile2(path, content, "utf8");
|
|
67330
67534
|
},
|
|
67331
67535
|
removeFile: async (path) => {
|
|
67332
67536
|
if (ig.ignores(path)) {
|
|
@@ -67338,7 +67542,7 @@ ${content}`;
|
|
|
67338
67542
|
if (ig.ignores(sourcePath) || ig.ignores(targetPath)) {
|
|
67339
67543
|
throw new Error(`Not allow to access file ${sourcePath} or ${targetPath}`);
|
|
67340
67544
|
}
|
|
67341
|
-
return await
|
|
67545
|
+
return await rename2(sourcePath, targetPath);
|
|
67342
67546
|
},
|
|
67343
67547
|
listFiles: async (path, recursive, maxCount, includeIgnored) => {
|
|
67344
67548
|
return await listFiles(path, recursive, maxCount, process.cwd(), options.excludeFiles, includeIgnored);
|
|
@@ -67350,7 +67554,7 @@ ${content}`;
|
|
|
67350
67554
|
if (!resolvedPath.startsWith(process.cwd())) {
|
|
67351
67555
|
throw new Error(`Access to file path "${filePath}" is restricted.`);
|
|
67352
67556
|
}
|
|
67353
|
-
const data2 = await
|
|
67557
|
+
const data2 = await readFile3(resolvedPath);
|
|
67354
67558
|
const mediaType2 = $lookup(resolvedPath) || "application/octet-stream";
|
|
67355
67559
|
return {
|
|
67356
67560
|
base64Data: data2.toString("base64"),
|
|
@@ -67478,10 +67682,10 @@ ${content}`;
|
|
|
67478
67682
|
};
|
|
67479
67683
|
// src/sqlite-memory-store.ts
|
|
67480
67684
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
67481
|
-
import { randomUUID } from "node:crypto";
|
|
67685
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
67482
67686
|
import { existsSync as existsSync3 } from "node:fs";
|
|
67483
|
-
import { mkdir as
|
|
67484
|
-
import { basename as basename2, dirname as
|
|
67687
|
+
import { mkdir as mkdir3, readdir, readFile as readFile4, rename as rename3, unlink as unlink2, writeFile as writeFile3 } from "node:fs/promises";
|
|
67688
|
+
import { basename as basename2, dirname as dirname4, resolve as resolve5 } from "node:path";
|
|
67485
67689
|
import { fileURLToPath } from "node:url";
|
|
67486
67690
|
var import_sql = __toESM(require_sql_wasm(), 1);
|
|
67487
67691
|
|
|
@@ -67504,7 +67708,7 @@ class FileLock {
|
|
|
67504
67708
|
}
|
|
67505
67709
|
FileLock.lastCleanupTime = now;
|
|
67506
67710
|
try {
|
|
67507
|
-
const lockDir =
|
|
67711
|
+
const lockDir = dirname4(dbPath);
|
|
67508
67712
|
const dbBaseName = basename2(dbPath);
|
|
67509
67713
|
const files = await readdir(lockDir);
|
|
67510
67714
|
const now2 = Date.now();
|
|
@@ -67541,7 +67745,7 @@ class FileLock {
|
|
|
67541
67745
|
pid: process.pid,
|
|
67542
67746
|
acquiredAt: Date.now()
|
|
67543
67747
|
});
|
|
67544
|
-
await
|
|
67748
|
+
await writeFile3(this.lockfilePath, lockData, {
|
|
67545
67749
|
flag: "wx",
|
|
67546
67750
|
mode: 384
|
|
67547
67751
|
});
|
|
@@ -67550,23 +67754,23 @@ class FileLock {
|
|
|
67550
67754
|
const errorCode = error48?.code;
|
|
67551
67755
|
if (errorCode === "EEXIST") {
|
|
67552
67756
|
try {
|
|
67553
|
-
const lockContent = await
|
|
67757
|
+
const lockContent = await readFile4(this.lockfilePath, "utf-8");
|
|
67554
67758
|
const lockData = JSON.parse(lockContent);
|
|
67555
67759
|
if (!lockData || typeof lockData.acquiredAt !== "number" || lockData.acquiredAt <= 0) {
|
|
67556
67760
|
console.warn(`[FileLock] Lock file has invalid acquiredAt, treating as stale`);
|
|
67557
|
-
await
|
|
67761
|
+
await rename3(this.lockfilePath, `${this.lockfilePath}.invalid.${Date.now()}`);
|
|
67558
67762
|
continue;
|
|
67559
67763
|
}
|
|
67560
67764
|
const lockAge = Date.now() - lockData.acquiredAt;
|
|
67561
67765
|
if (lockAge > FileLock.LOCK_TIMEOUT) {
|
|
67562
67766
|
console.warn(`[FileLock] Breaking stale lock (age: ${lockAge}ms)`);
|
|
67563
|
-
await
|
|
67767
|
+
await rename3(this.lockfilePath, `${this.lockfilePath}.stale.${Date.now()}`);
|
|
67564
67768
|
continue;
|
|
67565
67769
|
}
|
|
67566
67770
|
} catch (readError) {
|
|
67567
67771
|
if (readError instanceof SyntaxError) {
|
|
67568
67772
|
console.warn(`[FileLock] Lock file contains invalid JSON, treating as stale`);
|
|
67569
|
-
await
|
|
67773
|
+
await rename3(this.lockfilePath, `${this.lockfilePath}.corrupt.${Date.now()}`);
|
|
67570
67774
|
continue;
|
|
67571
67775
|
}
|
|
67572
67776
|
}
|
|
@@ -67583,7 +67787,7 @@ class FileLock {
|
|
|
67583
67787
|
}
|
|
67584
67788
|
async release() {
|
|
67585
67789
|
try {
|
|
67586
|
-
await
|
|
67790
|
+
await rename3(this.lockfilePath, `${this.lockfilePath}.released.${Date.now()}`);
|
|
67587
67791
|
const dbPath = this.lockfilePath.slice(0, -5);
|
|
67588
67792
|
FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
|
|
67589
67793
|
} catch (error48) {
|
|
@@ -67637,7 +67841,7 @@ async function getSqlJs() {
|
|
|
67637
67841
|
if (SqlJsInitPromise) {
|
|
67638
67842
|
return SqlJsInitPromise;
|
|
67639
67843
|
}
|
|
67640
|
-
const moduleDir =
|
|
67844
|
+
const moduleDir = dirname4(fileURLToPath(import.meta.url));
|
|
67641
67845
|
const candidates = [
|
|
67642
67846
|
resolve5(moduleDir, "sql-wasm.wasm"),
|
|
67643
67847
|
resolve5(moduleDir, "..", "dist", "sql-wasm.wasm"),
|
|
@@ -67703,9 +67907,9 @@ class SQLiteMemoryStore {
|
|
|
67703
67907
|
}
|
|
67704
67908
|
const dbPath = this.resolvePath(this.getDbPath());
|
|
67705
67909
|
try {
|
|
67706
|
-
const dir =
|
|
67910
|
+
const dir = dirname4(dbPath);
|
|
67707
67911
|
if (!existsSync3(dir)) {
|
|
67708
|
-
await
|
|
67912
|
+
await mkdir3(dir, { recursive: true, mode: 448 });
|
|
67709
67913
|
}
|
|
67710
67914
|
FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
|
|
67711
67915
|
let dbData;
|
|
@@ -67714,7 +67918,7 @@ class SQLiteMemoryStore {
|
|
|
67714
67918
|
await lock.acquire();
|
|
67715
67919
|
try {
|
|
67716
67920
|
try {
|
|
67717
|
-
dbData = await
|
|
67921
|
+
dbData = await readFile4(dbPath);
|
|
67718
67922
|
if (dbData.length >= 16) {
|
|
67719
67923
|
const header = String.fromCharCode(...dbData.subarray(0, 15));
|
|
67720
67924
|
if (header !== "SQLite format 3") {
|
|
@@ -67747,7 +67951,7 @@ class SQLiteMemoryStore {
|
|
|
67747
67951
|
const backupPath = `${dbPath}.corrupted.${Date.now()}`;
|
|
67748
67952
|
console.warn(`[SQLiteMemoryStore] Backing up corrupted database to: ${backupPath}`);
|
|
67749
67953
|
try {
|
|
67750
|
-
await
|
|
67954
|
+
await rename3(dbPath, backupPath);
|
|
67751
67955
|
} catch (backupError) {
|
|
67752
67956
|
console.error("[SQLiteMemoryStore] Failed to backup corrupted database:", backupError);
|
|
67753
67957
|
this.dbPromise = null;
|
|
@@ -67772,8 +67976,8 @@ class SQLiteMemoryStore {
|
|
|
67772
67976
|
const dbPath = this.resolvePath(this.getDbPath());
|
|
67773
67977
|
const tempPath = `${dbPath}.tmp`;
|
|
67774
67978
|
const data = this.db.export();
|
|
67775
|
-
await
|
|
67776
|
-
await
|
|
67979
|
+
await writeFile3(tempPath, data, { mode: 384 });
|
|
67980
|
+
await rename3(tempPath, dbPath);
|
|
67777
67981
|
} finally {
|
|
67778
67982
|
await lock.release();
|
|
67779
67983
|
}
|
|
@@ -67827,7 +68031,7 @@ class SQLiteMemoryStore {
|
|
|
67827
68031
|
return resolve5(resolved);
|
|
67828
68032
|
}
|
|
67829
68033
|
generateUUID() {
|
|
67830
|
-
return
|
|
68034
|
+
return randomUUID2();
|
|
67831
68035
|
}
|
|
67832
68036
|
now() {
|
|
67833
68037
|
return Date.now();
|