@polka-codes/cli-shared 0.9.100 → 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.
Files changed (2) hide show
  1. package/dist/index.js +279 -74
  2. 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 randomUUID = async () => globalThis.crypto?.randomUUID() || (await import("crypto")).randomUUID();
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 (shouldRetry && config3) {
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 randomUUID();
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 readFile2 = fs3.readFile ? (0, _util.promisify)(fs3.readFile) : /* @__PURE__ */ _asyncToGenerator(/* @__PURE__ */ _regenerator().m(function _callee() {
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 readFile2(keyFile, "utf8");
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 readFile2(keyFile, "utf8");
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 readFile2 = (0, util_1.promisify)(fs3.readFile ?? (() => {}));
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 readFile2(parsedFilePath, { encoding: "utf8" });
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, {
@@ -51099,8 +51099,182 @@ var configSchema = exports_external.object({
51099
51099
  rules: exports_external.array(ruleSchema).optional().or(exports_external.string()).optional(),
51100
51100
  excludeFiles: exports_external.array(exports_external.string()).optional(),
51101
51101
  agent: agentSchema,
51102
- memory: memoryConfigSchema
51102
+ memory: memoryConfigSchema,
51103
+ loadRules: exports_external.record(exports_external.string(), exports_external.boolean()).optional()
51103
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
+ }
51104
51278
  // ../core/src/skills/constants.ts
51105
51279
  var SKILL_LIMITS = {
51106
51280
  MAX_FILE_SIZE: 1024 * 1024,
@@ -52334,9 +52508,11 @@ var writeToFile_default = {
52334
52508
  class UsageMeter {
52335
52509
  #totals = { input: 0, output: 0, cachedRead: 0, cost: 0, messageCount: 0 };
52336
52510
  #providerMetadataEntries = [];
52511
+ #pendingUpdates = new Set;
52337
52512
  #modelInfos;
52338
52513
  #maxMessages;
52339
52514
  #maxCost;
52515
+ #pricingService;
52340
52516
  constructor(modelInfos = {}, opts = {}) {
52341
52517
  const infos = {};
52342
52518
  for (const [provider2, providerInfo] of Object.entries(modelInfos)) {
@@ -52352,6 +52528,7 @@ class UsageMeter {
52352
52528
  this.#modelInfos = infos;
52353
52529
  this.#maxMessages = opts.maxMessages ?? 1000;
52354
52530
  this.#maxCost = opts.maxCost ?? 100;
52531
+ this.#pricingService = opts.pricingService;
52355
52532
  }
52356
52533
  #calculateUsage(usage, providerMetadata, modelInfo) {
52357
52534
  const providerMetadataKey = Object.keys(providerMetadata ?? {})[0];
@@ -52402,28 +52579,52 @@ class UsageMeter {
52402
52579
  }
52403
52580
  }
52404
52581
  addUsage(llm, resp, options = {}) {
52405
- const modelInfo = options.modelInfo ?? this.#modelInfos[`${llm.provider.split(".")[0]}:${llm.modelId.replace(/[.-]/g, "")}`] ?? {
52406
- inputPrice: 0,
52407
- outputPrice: 0,
52408
- cacheWritesPrice: 0,
52409
- cacheReadsPrice: 0
52410
- };
52411
- const usage = "totalUsage" in resp ? resp.totalUsage : resp.usage;
52412
- const result = this.#calculateUsage(usage, resp.providerMetadata, modelInfo);
52413
- this.#totals.input += result.input || 0;
52414
- this.#totals.output += result.output || 0;
52415
- this.#totals.cachedRead += result.cachedRead || 0;
52416
- this.#totals.cost += result.cost || 0;
52417
- this.#totals.messageCount += 1;
52418
- if (resp.providerMetadata && Object.keys(resp.providerMetadata).length > 0) {
52419
- const providerKey = Object.keys(resp.providerMetadata)[0];
52420
- this.#providerMetadataEntries.push({
52421
- provider: providerKey || llm.provider,
52422
- model: llm.modelId,
52423
- metadata: resp.providerMetadata[providerKey] || resp.providerMetadata,
52424
- timestamp: Date.now()
52425
- });
52426
- }
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;
52427
52628
  }
52428
52629
  setUsage(newUsage, options = {}) {
52429
52630
  if (newUsage.input != null)
@@ -52507,13 +52708,17 @@ class UsageMeter {
52507
52708
  this.#totals.messageCount += otherUsage.messageCount;
52508
52709
  this.#providerMetadataEntries.push(...other.providerMetadata);
52509
52710
  }
52711
+ async waitForPending() {
52712
+ const pending = Array.from(this.#pendingUpdates);
52713
+ await Promise.allSettled(pending);
52714
+ }
52510
52715
  getUsageText() {
52511
52716
  const u = this.usage;
52512
52717
  return `Usage - messages: ${u.messageCount}, input: ${u.input}, cached: ${u.cachedRead}, output: ${u.output}, cost: $${u.cost.toFixed(4)}`;
52513
52718
  }
52514
52719
  onFinishHandler(llm) {
52515
- return (evt) => {
52516
- this.addUsage(llm, evt);
52720
+ return async (evt) => {
52721
+ await this.addUsage(llm, evt);
52517
52722
  };
52518
52723
  }
52519
52724
  }
@@ -63316,8 +63521,8 @@ var merge2 = _createAssigner_default(function(object3, source, srcIndex) {
63316
63521
  });
63317
63522
  var merge_default = merge2;
63318
63523
  // src/config.ts
63319
- function getGlobalConfigPath(home = homedir()) {
63320
- return join(home, ".config", "polkacodes", "config.yml");
63524
+ function getGlobalConfigPath(home = homedir2()) {
63525
+ return join2(home, ".config", "polkacodes", "config.yml");
63321
63526
  }
63322
63527
  function loadConfigAtPath(path) {
63323
63528
  try {
@@ -63405,7 +63610,7 @@ async function resolveRules(rules) {
63405
63610
  }
63406
63611
  } else if ("path" in rule) {
63407
63612
  if (existsSync(rule.path)) {
63408
- return await readFile(rule.path, "utf-8");
63613
+ return await readFile2(rule.path, "utf-8");
63409
63614
  }
63410
63615
  console.warn(`Rule file not found: ${rule.path}`);
63411
63616
  }
@@ -63415,7 +63620,7 @@ async function resolveRules(rules) {
63415
63620
 
63416
63621
  `);
63417
63622
  }
63418
- async function loadConfig(paths, cwd = process.cwd(), home = homedir()) {
63623
+ async function loadConfig(paths, cwd = process.cwd(), home = homedir2()) {
63419
63624
  const configs = [];
63420
63625
  const globalConfigPath = getGlobalConfigPath(home);
63421
63626
  if (existsSync(globalConfigPath)) {
@@ -63444,7 +63649,7 @@ ${error48}`);
63444
63649
  }
63445
63650
  }
63446
63651
  } else {
63447
- const configPath = join(cwd, localConfigFileName);
63652
+ const configPath = join2(cwd, localConfigFileName);
63448
63653
  try {
63449
63654
  const projectConfig = readConfig(configPath);
63450
63655
  configs.push(projectConfig);
@@ -63528,7 +63733,7 @@ class MemoryManager {
63528
63733
  }
63529
63734
  // src/project-scope.ts
63530
63735
  import { existsSync as existsSync2 } from "node:fs";
63531
- import { dirname, normalize, resolve as resolve2, sep } from "node:path";
63736
+ import { dirname as dirname2, normalize, resolve as resolve2, sep } from "node:path";
63532
63737
  function detectProjectScope(cwd) {
63533
63738
  const projectPath = findProjectRoot(cwd);
63534
63739
  if (!projectPath) {
@@ -63562,7 +63767,7 @@ function findProjectRoot(dir) {
63562
63767
  return dir;
63563
63768
  }
63564
63769
  }
63565
- const parent = dirname(dir);
63770
+ const parent = dirname2(dir);
63566
63771
  if (parent === dir) {
63567
63772
  return null;
63568
63773
  }
@@ -63573,8 +63778,8 @@ function normalizePath(path) {
63573
63778
  }
63574
63779
  // src/provider.ts
63575
63780
  import { spawn as spawn2 } from "node:child_process";
63576
- import { mkdir, readFile as readFile2, rename, unlink, writeFile } from "node:fs/promises";
63577
- import { dirname as dirname2, normalize as normalize2, resolve as resolve4 } from "node:path";
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";
63578
63783
 
63579
63784
  // ../../node_modules/@ai-sdk/google-vertex/dist/index.mjs
63580
63785
  var import_google_auth_library = __toESM(require_src7(), 1);
@@ -66990,7 +67195,7 @@ function checkRipgrep() {
66990
67195
  // src/utils/listFiles.ts
66991
67196
  var import_ignore = __toESM(require_ignore(), 1);
66992
67197
  import { promises as fs3 } from "node:fs";
66993
- import { join as join2, relative, resolve as resolve3 } from "node:path";
67198
+ import { join as join3, relative, resolve as resolve3 } from "node:path";
66994
67199
  var DEFAULT_IGNORES = [
66995
67200
  "__pycache__",
66996
67201
  ".DS_Store",
@@ -67008,7 +67213,7 @@ var DEFAULT_IGNORES = [
67008
67213
  ];
67009
67214
  async function extendPatterns(basePatterns, dirPath) {
67010
67215
  try {
67011
- const gitignorePath = join2(dirPath, ".gitignore");
67216
+ const gitignorePath = join3(dirPath, ".gitignore");
67012
67217
  const content = await fs3.readFile(gitignorePath, "utf8");
67013
67218
  const lines = content.split(/\r?\n/).filter(Boolean);
67014
67219
  return [...basePatterns, ...lines];
@@ -67024,7 +67229,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
67024
67229
  if (!includeIgnored) {
67025
67230
  rootPatterns.push(...DEFAULT_IGNORES);
67026
67231
  try {
67027
- const rootGitignore = await fs3.readFile(join2(cwd, ".gitignore"), "utf8");
67232
+ const rootGitignore = await fs3.readFile(join3(cwd, ".gitignore"), "utf8");
67028
67233
  const lines = rootGitignore.split(/\r?\n/).filter(Boolean);
67029
67234
  rootPatterns = [...rootPatterns, ...lines];
67030
67235
  } catch {}
@@ -67046,7 +67251,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
67046
67251
  const entries = await fs3.readdir(currentPath, { withFileTypes: true });
67047
67252
  entries.sort((a, b) => a.name.localeCompare(b.name));
67048
67253
  for (const entry of entries) {
67049
- const fullPath = join2(currentPath, entry.name);
67254
+ const fullPath = join3(currentPath, entry.name);
67050
67255
  const relPath = relative(cwd, fullPath).replace(/\\/g, "/");
67051
67256
  if (folderIg.ignores(relPath)) {
67052
67257
  continue;
@@ -67063,7 +67268,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
67063
67268
  results.push(relPath);
67064
67269
  if (results.length >= maxCount) {
67065
67270
  const remainingEntries = entries.slice(entries.indexOf(entry) + 1);
67066
- const hasRemainingFiles = remainingEntries.some((e2) => !e2.isDirectory() && !folderIg.ignores(relative(cwd, join2(currentPath, e2.name)).replace(/\\/g, "/")));
67271
+ const hasRemainingFiles = remainingEntries.some((e2) => !e2.isDirectory() && !folderIg.ignores(relative(cwd, join3(currentPath, e2.name)).replace(/\\/g, "/")));
67067
67272
  if (hasRemainingFiles) {
67068
67273
  const marker16 = `${currentRelPath}/(files omitted)`;
67069
67274
  results.push(marker16);
@@ -67315,7 +67520,7 @@ ${content}`;
67315
67520
  throw new Error(`Not allow to access file ${path}`);
67316
67521
  }
67317
67522
  try {
67318
- return await readFile2(path, "utf8");
67523
+ return await readFile3(path, "utf8");
67319
67524
  } catch (_e) {
67320
67525
  return;
67321
67526
  }
@@ -67324,8 +67529,8 @@ ${content}`;
67324
67529
  if (ig.ignores(path)) {
67325
67530
  throw new Error(`Not allow to access file ${path}`);
67326
67531
  }
67327
- await mkdir(dirname2(path), { recursive: true });
67328
- return await writeFile(path, content, "utf8");
67532
+ await mkdir2(dirname3(path), { recursive: true });
67533
+ return await writeFile2(path, content, "utf8");
67329
67534
  },
67330
67535
  removeFile: async (path) => {
67331
67536
  if (ig.ignores(path)) {
@@ -67337,7 +67542,7 @@ ${content}`;
67337
67542
  if (ig.ignores(sourcePath) || ig.ignores(targetPath)) {
67338
67543
  throw new Error(`Not allow to access file ${sourcePath} or ${targetPath}`);
67339
67544
  }
67340
- return await rename(sourcePath, targetPath);
67545
+ return await rename2(sourcePath, targetPath);
67341
67546
  },
67342
67547
  listFiles: async (path, recursive, maxCount, includeIgnored) => {
67343
67548
  return await listFiles(path, recursive, maxCount, process.cwd(), options.excludeFiles, includeIgnored);
@@ -67349,7 +67554,7 @@ ${content}`;
67349
67554
  if (!resolvedPath.startsWith(process.cwd())) {
67350
67555
  throw new Error(`Access to file path "${filePath}" is restricted.`);
67351
67556
  }
67352
- const data2 = await readFile2(resolvedPath);
67557
+ const data2 = await readFile3(resolvedPath);
67353
67558
  const mediaType2 = $lookup(resolvedPath) || "application/octet-stream";
67354
67559
  return {
67355
67560
  base64Data: data2.toString("base64"),
@@ -67477,10 +67682,10 @@ ${content}`;
67477
67682
  };
67478
67683
  // src/sqlite-memory-store.ts
67479
67684
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
67480
- import { randomUUID } from "node:crypto";
67685
+ import { randomUUID as randomUUID2 } from "node:crypto";
67481
67686
  import { existsSync as existsSync3 } from "node:fs";
67482
- import { mkdir as mkdir2, readdir, readFile as readFile3, rename as rename2, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
67483
- import { basename as basename2, dirname as dirname3, resolve as resolve5 } from "node:path";
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";
67484
67689
  import { fileURLToPath } from "node:url";
67485
67690
  var import_sql = __toESM(require_sql_wasm(), 1);
67486
67691
 
@@ -67503,7 +67708,7 @@ class FileLock {
67503
67708
  }
67504
67709
  FileLock.lastCleanupTime = now;
67505
67710
  try {
67506
- const lockDir = dirname3(dbPath);
67711
+ const lockDir = dirname4(dbPath);
67507
67712
  const dbBaseName = basename2(dbPath);
67508
67713
  const files = await readdir(lockDir);
67509
67714
  const now2 = Date.now();
@@ -67540,7 +67745,7 @@ class FileLock {
67540
67745
  pid: process.pid,
67541
67746
  acquiredAt: Date.now()
67542
67747
  });
67543
- await writeFile2(this.lockfilePath, lockData, {
67748
+ await writeFile3(this.lockfilePath, lockData, {
67544
67749
  flag: "wx",
67545
67750
  mode: 384
67546
67751
  });
@@ -67549,23 +67754,23 @@ class FileLock {
67549
67754
  const errorCode = error48?.code;
67550
67755
  if (errorCode === "EEXIST") {
67551
67756
  try {
67552
- const lockContent = await readFile3(this.lockfilePath, "utf-8");
67757
+ const lockContent = await readFile4(this.lockfilePath, "utf-8");
67553
67758
  const lockData = JSON.parse(lockContent);
67554
67759
  if (!lockData || typeof lockData.acquiredAt !== "number" || lockData.acquiredAt <= 0) {
67555
67760
  console.warn(`[FileLock] Lock file has invalid acquiredAt, treating as stale`);
67556
- await rename2(this.lockfilePath, `${this.lockfilePath}.invalid.${Date.now()}`);
67761
+ await rename3(this.lockfilePath, `${this.lockfilePath}.invalid.${Date.now()}`);
67557
67762
  continue;
67558
67763
  }
67559
67764
  const lockAge = Date.now() - lockData.acquiredAt;
67560
67765
  if (lockAge > FileLock.LOCK_TIMEOUT) {
67561
67766
  console.warn(`[FileLock] Breaking stale lock (age: ${lockAge}ms)`);
67562
- await rename2(this.lockfilePath, `${this.lockfilePath}.stale.${Date.now()}`);
67767
+ await rename3(this.lockfilePath, `${this.lockfilePath}.stale.${Date.now()}`);
67563
67768
  continue;
67564
67769
  }
67565
67770
  } catch (readError) {
67566
67771
  if (readError instanceof SyntaxError) {
67567
67772
  console.warn(`[FileLock] Lock file contains invalid JSON, treating as stale`);
67568
- await rename2(this.lockfilePath, `${this.lockfilePath}.corrupt.${Date.now()}`);
67773
+ await rename3(this.lockfilePath, `${this.lockfilePath}.corrupt.${Date.now()}`);
67569
67774
  continue;
67570
67775
  }
67571
67776
  }
@@ -67582,7 +67787,7 @@ class FileLock {
67582
67787
  }
67583
67788
  async release() {
67584
67789
  try {
67585
- await rename2(this.lockfilePath, `${this.lockfilePath}.released.${Date.now()}`);
67790
+ await rename3(this.lockfilePath, `${this.lockfilePath}.released.${Date.now()}`);
67586
67791
  const dbPath = this.lockfilePath.slice(0, -5);
67587
67792
  FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
67588
67793
  } catch (error48) {
@@ -67636,7 +67841,7 @@ async function getSqlJs() {
67636
67841
  if (SqlJsInitPromise) {
67637
67842
  return SqlJsInitPromise;
67638
67843
  }
67639
- const moduleDir = dirname3(fileURLToPath(import.meta.url));
67844
+ const moduleDir = dirname4(fileURLToPath(import.meta.url));
67640
67845
  const candidates = [
67641
67846
  resolve5(moduleDir, "sql-wasm.wasm"),
67642
67847
  resolve5(moduleDir, "..", "dist", "sql-wasm.wasm"),
@@ -67702,9 +67907,9 @@ class SQLiteMemoryStore {
67702
67907
  }
67703
67908
  const dbPath = this.resolvePath(this.getDbPath());
67704
67909
  try {
67705
- const dir = dirname3(dbPath);
67910
+ const dir = dirname4(dbPath);
67706
67911
  if (!existsSync3(dir)) {
67707
- await mkdir2(dir, { recursive: true, mode: 448 });
67912
+ await mkdir3(dir, { recursive: true, mode: 448 });
67708
67913
  }
67709
67914
  FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
67710
67915
  let dbData;
@@ -67713,7 +67918,7 @@ class SQLiteMemoryStore {
67713
67918
  await lock.acquire();
67714
67919
  try {
67715
67920
  try {
67716
- dbData = await readFile3(dbPath);
67921
+ dbData = await readFile4(dbPath);
67717
67922
  if (dbData.length >= 16) {
67718
67923
  const header = String.fromCharCode(...dbData.subarray(0, 15));
67719
67924
  if (header !== "SQLite format 3") {
@@ -67746,7 +67951,7 @@ class SQLiteMemoryStore {
67746
67951
  const backupPath = `${dbPath}.corrupted.${Date.now()}`;
67747
67952
  console.warn(`[SQLiteMemoryStore] Backing up corrupted database to: ${backupPath}`);
67748
67953
  try {
67749
- await rename2(dbPath, backupPath);
67954
+ await rename3(dbPath, backupPath);
67750
67955
  } catch (backupError) {
67751
67956
  console.error("[SQLiteMemoryStore] Failed to backup corrupted database:", backupError);
67752
67957
  this.dbPromise = null;
@@ -67771,8 +67976,8 @@ class SQLiteMemoryStore {
67771
67976
  const dbPath = this.resolvePath(this.getDbPath());
67772
67977
  const tempPath = `${dbPath}.tmp`;
67773
67978
  const data = this.db.export();
67774
- await writeFile2(tempPath, data, { mode: 384 });
67775
- await rename2(tempPath, dbPath);
67979
+ await writeFile3(tempPath, data, { mode: 384 });
67980
+ await rename3(tempPath, dbPath);
67776
67981
  } finally {
67777
67982
  await lock.release();
67778
67983
  }
@@ -67826,7 +68031,7 @@ class SQLiteMemoryStore {
67826
68031
  return resolve5(resolved);
67827
68032
  }
67828
68033
  generateUUID() {
67829
- return randomUUID();
68034
+ return randomUUID2();
67830
68035
  }
67831
68036
  now() {
67832
68037
  return Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli-shared",
3
- "version": "0.9.100",
3
+ "version": "0.9.102",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",