@polka-codes/runner 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.
Files changed (2) hide show
  1. package/dist/index.js +276 -72
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -19054,7 +19054,7 @@ var require_gaxios = __commonJS((exports) => {
19054
19054
  var retry_js_1 = require_retry();
19055
19055
  var stream_1 = __require("stream");
19056
19056
  var interceptor_js_1 = require_interceptor();
19057
- var randomUUID = async () => globalThis.crypto?.randomUUID() || (await import("crypto")).randomUUID();
19057
+ var randomUUID2 = async () => globalThis.crypto?.randomUUID() || (await import("crypto")).randomUUID();
19058
19058
  var HTTP_STATUS_NO_CONTENT = 204;
19059
19059
 
19060
19060
  class Gaxios {
@@ -19144,8 +19144,8 @@ var require_gaxios = __commonJS((exports) => {
19144
19144
  } else {
19145
19145
  err = new common_js_1.GaxiosError("Unexpected Gaxios Error", opts, undefined, e2);
19146
19146
  }
19147
- const { shouldRetry, config: config3 } = await (0, retry_js_1.getRetryConfig)(err);
19148
- if (shouldRetry && config3) {
19147
+ const { shouldRetry: shouldRetry2, config: config3 } = await (0, retry_js_1.getRetryConfig)(err);
19148
+ if (shouldRetry2 && config3) {
19149
19149
  err.config.retryConfig.currentRetryAttempt = config3.retryConfig.currentRetryAttempt;
19150
19150
  opts.retryConfig = err.config?.retryConfig;
19151
19151
  this.#appendTimeoutToSignal(opts);
@@ -19265,7 +19265,7 @@ var require_gaxios = __commonJS((exports) => {
19265
19265
  }
19266
19266
  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 || "");
19267
19267
  if (opts.multipart?.length) {
19268
- const boundary = await randomUUID();
19268
+ const boundary = await randomUUID2();
19269
19269
  preparedHeaders.set("content-type", `multipart/related; boundary=${boundary}`);
19270
19270
  opts.body = stream_1.Readable.from(this.getMultipartRequest(opts.multipart, boundary));
19271
19271
  } else if (shouldDirectlyPassData) {
@@ -24405,7 +24405,7 @@ var require_src6 = __commonJS((exports) => {
24405
24405
  });
24406
24406
  };
24407
24407
  }
24408
- var readFile2 = fs3.readFile ? (0, _util.promisify)(fs3.readFile) : /* @__PURE__ */ _asyncToGenerator(/* @__PURE__ */ _regenerator().m(function _callee() {
24408
+ var readFile3 = fs3.readFile ? (0, _util.promisify)(fs3.readFile) : /* @__PURE__ */ _asyncToGenerator(/* @__PURE__ */ _regenerator().m(function _callee() {
24409
24409
  return _regenerator().w(function(_context) {
24410
24410
  while (true)
24411
24411
  switch (_context.n) {
@@ -24532,7 +24532,7 @@ var require_src6 = __commonJS((exports) => {
24532
24532
  break;
24533
24533
  case 1:
24534
24534
  _context2.n = 2;
24535
- return readFile2(keyFile, "utf8");
24535
+ return readFile3(keyFile, "utf8");
24536
24536
  case 2:
24537
24537
  key = _context2.v;
24538
24538
  body = JSON.parse(key);
@@ -24550,7 +24550,7 @@ var require_src6 = __commonJS((exports) => {
24550
24550
  });
24551
24551
  case 4:
24552
24552
  _context2.n = 5;
24553
- return readFile2(keyFile, "utf8");
24553
+ return readFile3(keyFile, "utf8");
24554
24554
  case 5:
24555
24555
  _privateKey = _context2.v;
24556
24556
  return _context2.a(2, {
@@ -25788,7 +25788,7 @@ var require_filesubjecttokensupplier = __commonJS((exports) => {
25788
25788
  exports.FileSubjectTokenSupplier = undefined;
25789
25789
  var util_1 = __require("util");
25790
25790
  var fs3 = __require("fs");
25791
- var readFile2 = (0, util_1.promisify)(fs3.readFile ?? (() => {}));
25791
+ var readFile3 = (0, util_1.promisify)(fs3.readFile ?? (() => {}));
25792
25792
  var realpath = (0, util_1.promisify)(fs3.realpath ?? (() => {}));
25793
25793
  var lstat = (0, util_1.promisify)(fs3.lstat ?? (() => {}));
25794
25794
 
@@ -25815,7 +25815,7 @@ var require_filesubjecttokensupplier = __commonJS((exports) => {
25815
25815
  throw err;
25816
25816
  }
25817
25817
  let subjectToken;
25818
- const rawText = await readFile2(parsedFilePath, { encoding: "utf8" });
25818
+ const rawText = await readFile3(parsedFilePath, { encoding: "utf8" });
25819
25819
  if (this.formatType === "text") {
25820
25820
  subjectToken = rawText;
25821
25821
  } else if (this.formatType === "json" && this.subjectTokenFieldName) {
@@ -42783,7 +42783,7 @@ var {
42783
42783
  Help
42784
42784
  } = import__.default;
42785
42785
  // package.json
42786
- var version = "0.9.101";
42786
+ var version = "0.9.102";
42787
42787
 
42788
42788
  // src/runner.ts
42789
42789
  import { execSync } from "node:child_process";
@@ -42791,9 +42791,9 @@ import { promises as fs4 } from "node:fs";
42791
42791
 
42792
42792
  // ../cli-shared/src/config.ts
42793
42793
  import { existsSync, readFileSync } from "node:fs";
42794
- import { readFile } from "node:fs/promises";
42795
- import { homedir } from "node:os";
42796
- import { join } from "node:path";
42794
+ import { readFile as readFile2 } from "node:fs/promises";
42795
+ import { homedir as homedir2 } from "node:os";
42796
+ import { join as join2 } from "node:path";
42797
42797
  // ../core/src/Agent/prompts.ts
42798
42798
  var responsePrompts = {
42799
42799
  errorInvokeTool: (tool, error) => `An error occurred while invoking the tool "${tool}": ${error}`,
@@ -56584,6 +56584,179 @@ var configSchema = exports_external.object({
56584
56584
  memory: memoryConfigSchema,
56585
56585
  loadRules: exports_external.record(exports_external.string(), exports_external.boolean()).optional()
56586
56586
  }).strict().nullish();
56587
+ // ../core/src/pricing/pricing-service.ts
56588
+ import { randomUUID } from "node:crypto";
56589
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
56590
+ import { homedir } from "node:os";
56591
+ import { dirname, join } from "node:path";
56592
+
56593
+ // ../core/src/pricing/converter.ts
56594
+ function convertPortkeyToModelInfo(portkey) {
56595
+ return {
56596
+ inputPrice: (portkey.request_token?.price ?? 0) * 10,
56597
+ outputPrice: (portkey.response_token?.price ?? 0) * 10,
56598
+ cacheWritesPrice: (portkey.cache_write_input_token?.price ?? 0) * 10,
56599
+ cacheReadsPrice: (portkey.cache_read_input_token?.price ?? 0) * 10
56600
+ };
56601
+ }
56602
+
56603
+ // ../core/src/pricing/portkey-client.ts
56604
+ var PORTKEY_BASE_URL = "https://api.portkey.ai/model-configs/pricing";
56605
+ var TIMEOUT_MS = 5000;
56606
+ var MAX_RETRIES = 2;
56607
+ async function fetchWithTimeout(url2, timeoutMs) {
56608
+ const controller = new AbortController;
56609
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
56610
+ try {
56611
+ const response = await fetch(url2, { signal: controller.signal });
56612
+ return response;
56613
+ } finally {
56614
+ clearTimeout(timeout);
56615
+ }
56616
+ }
56617
+ async function sleep(ms) {
56618
+ return new Promise((resolve) => setTimeout(resolve, ms));
56619
+ }
56620
+ function shouldRetry(response, error48) {
56621
+ if (error48)
56622
+ return true;
56623
+ if (response.status >= 500)
56624
+ return true;
56625
+ return false;
56626
+ }
56627
+ async function fetchPricing(provider, model) {
56628
+ const url2 = `${PORTKEY_BASE_URL}/${provider}/${model}`;
56629
+ for (let attempt = 0;attempt <= MAX_RETRIES; attempt++) {
56630
+ try {
56631
+ const response = await fetchWithTimeout(url2, TIMEOUT_MS);
56632
+ if (!response.ok) {
56633
+ if (!shouldRetry(response, null)) {
56634
+ return null;
56635
+ }
56636
+ if (attempt < MAX_RETRIES) {
56637
+ await sleep(2 ** attempt * 1000);
56638
+ continue;
56639
+ }
56640
+ return null;
56641
+ }
56642
+ const data = await response.json();
56643
+ return data;
56644
+ } catch (error48) {
56645
+ if (attempt < MAX_RETRIES && shouldRetry(new Response(null, { status: 500 }), error48)) {
56646
+ await sleep(2 ** attempt * 1000);
56647
+ continue;
56648
+ }
56649
+ return null;
56650
+ }
56651
+ }
56652
+ return null;
56653
+ }
56654
+
56655
+ // ../core/src/pricing/pricing-service.ts
56656
+ var CACHE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
56657
+
56658
+ class PricingService {
56659
+ #fallbackPrices;
56660
+ #cacheFile;
56661
+ #cache = null;
56662
+ #loadPromise = null;
56663
+ constructor(fallbackPrices = {}) {
56664
+ const normalized = {};
56665
+ for (const [provider, providerInfo] of Object.entries(fallbackPrices)) {
56666
+ const normalizedProvider = provider.split("-")[0];
56667
+ normalized[normalizedProvider] = {};
56668
+ for (const [model, modelInfo] of Object.entries(providerInfo)) {
56669
+ const normalizedModel = model.replace(/[.-]/g, "");
56670
+ normalized[normalizedProvider][normalizedModel] = {
56671
+ inputPrice: modelInfo.inputPrice ?? 0,
56672
+ outputPrice: modelInfo.outputPrice ?? 0,
56673
+ cacheWritesPrice: modelInfo.cacheWritesPrice ?? 0,
56674
+ cacheReadsPrice: modelInfo.cacheReadsPrice ?? 0
56675
+ };
56676
+ }
56677
+ }
56678
+ this.#fallbackPrices = normalized;
56679
+ this.#cacheFile = join(homedir(), ".config", "polkacodes", "pricing-cache.json");
56680
+ }
56681
+ async#load() {
56682
+ if (this.#loadPromise) {
56683
+ return this.#loadPromise;
56684
+ }
56685
+ this.#loadPromise = (async () => {
56686
+ this.#cache = new Map;
56687
+ try {
56688
+ const content = await readFile(this.#cacheFile, "utf-8");
56689
+ const data = JSON.parse(content);
56690
+ for (const [key, value] of Object.entries(data)) {
56691
+ this.#cache.set(key, value);
56692
+ }
56693
+ } catch {}
56694
+ })();
56695
+ return this.#loadPromise;
56696
+ }
56697
+ async#get(provider, model) {
56698
+ await this.#load();
56699
+ const key = `${provider}:${model}`;
56700
+ const entry = this.#cache?.get(key);
56701
+ if (!entry) {
56702
+ return null;
56703
+ }
56704
+ if (Date.now() - entry.timestamp > CACHE_TTL_MS) {
56705
+ this.#cache?.delete(key);
56706
+ return null;
56707
+ }
56708
+ return entry.pricing;
56709
+ }
56710
+ async#set(provider, model, pricing) {
56711
+ await this.#load();
56712
+ const key = `${provider}:${model}`;
56713
+ this.#cache?.set(key, {
56714
+ pricing,
56715
+ timestamp: Date.now()
56716
+ });
56717
+ await this.#save();
56718
+ }
56719
+ async#save() {
56720
+ if (!this.#cache) {
56721
+ return;
56722
+ }
56723
+ try {
56724
+ const dir = dirname(this.#cacheFile);
56725
+ await mkdir(dir, { recursive: true });
56726
+ const data = {};
56727
+ for (const [key, value] of this.#cache.entries()) {
56728
+ data[key] = value;
56729
+ }
56730
+ const tempFile = `${this.#cacheFile}.${randomUUID()}.tmp`;
56731
+ await writeFile(tempFile, JSON.stringify(data, null, 2), "utf-8");
56732
+ await rename(tempFile, this.#cacheFile);
56733
+ } catch {}
56734
+ }
56735
+ async getPricing(provider, model) {
56736
+ const normalizedProvider = provider.split("-")[0];
56737
+ const normalizedModel = model.replace(/[.-]/g, "");
56738
+ const cached2 = await this.#get(normalizedProvider, normalizedModel);
56739
+ if (cached2) {
56740
+ return cached2;
56741
+ }
56742
+ const fallbackPrice = this.#fallbackPrices[normalizedProvider]?.[normalizedModel];
56743
+ if (fallbackPrice) {
56744
+ return fallbackPrice;
56745
+ }
56746
+ const portkeyPricing = await fetchPricing(normalizedProvider, model);
56747
+ if (portkeyPricing) {
56748
+ const modelInfo = convertPortkeyToModelInfo(portkeyPricing);
56749
+ await this.#set(normalizedProvider, normalizedModel, modelInfo);
56750
+ return modelInfo;
56751
+ }
56752
+ return {
56753
+ inputPrice: 0,
56754
+ outputPrice: 0,
56755
+ cacheWritesPrice: 0,
56756
+ cacheReadsPrice: 0
56757
+ };
56758
+ }
56759
+ }
56587
56760
  // ../core/src/skills/constants.ts
56588
56761
  var SKILL_LIMITS = {
56589
56762
  MAX_FILE_SIZE: 1024 * 1024,
@@ -57817,9 +57990,11 @@ var writeToFile_default = {
57817
57990
  class UsageMeter {
57818
57991
  #totals = { input: 0, output: 0, cachedRead: 0, cost: 0, messageCount: 0 };
57819
57992
  #providerMetadataEntries = [];
57993
+ #pendingUpdates = new Set;
57820
57994
  #modelInfos;
57821
57995
  #maxMessages;
57822
57996
  #maxCost;
57997
+ #pricingService;
57823
57998
  constructor(modelInfos = {}, opts = {}) {
57824
57999
  const infos = {};
57825
58000
  for (const [provider2, providerInfo] of Object.entries(modelInfos)) {
@@ -57835,6 +58010,7 @@ class UsageMeter {
57835
58010
  this.#modelInfos = infos;
57836
58011
  this.#maxMessages = opts.maxMessages ?? 1000;
57837
58012
  this.#maxCost = opts.maxCost ?? 100;
58013
+ this.#pricingService = opts.pricingService;
57838
58014
  }
57839
58015
  #calculateUsage(usage, providerMetadata, modelInfo) {
57840
58016
  const providerMetadataKey = Object.keys(providerMetadata ?? {})[0];
@@ -57885,28 +58061,52 @@ class UsageMeter {
57885
58061
  }
57886
58062
  }
57887
58063
  addUsage(llm, resp, options = {}) {
57888
- const modelInfo = options.modelInfo ?? this.#modelInfos[`${llm.provider.split(".")[0]}:${llm.modelId.replace(/[.-]/g, "")}`] ?? {
57889
- inputPrice: 0,
57890
- outputPrice: 0,
57891
- cacheWritesPrice: 0,
57892
- cacheReadsPrice: 0
57893
- };
57894
- const usage = "totalUsage" in resp ? resp.totalUsage : resp.usage;
57895
- const result = this.#calculateUsage(usage, resp.providerMetadata, modelInfo);
57896
- this.#totals.input += result.input || 0;
57897
- this.#totals.output += result.output || 0;
57898
- this.#totals.cachedRead += result.cachedRead || 0;
57899
- this.#totals.cost += result.cost || 0;
57900
- this.#totals.messageCount += 1;
57901
- if (resp.providerMetadata && Object.keys(resp.providerMetadata).length > 0) {
57902
- const providerKey = Object.keys(resp.providerMetadata)[0];
57903
- this.#providerMetadataEntries.push({
57904
- provider: providerKey || llm.provider,
57905
- model: llm.modelId,
57906
- metadata: resp.providerMetadata[providerKey] || resp.providerMetadata,
57907
- timestamp: Date.now()
57908
- });
57909
- }
58064
+ const provider2 = llm.provider.split(".")[0];
58065
+ const normalizedModel = llm.modelId.replace(/[.-]/g, "");
58066
+ const key = `${provider2}:${normalizedModel}`;
58067
+ let modelInfo = options.modelInfo ?? this.#modelInfos[key];
58068
+ const updatePromise = (async () => {
58069
+ try {
58070
+ if (!modelInfo && this.#pricingService) {
58071
+ modelInfo = await this.#pricingService.getPricing(provider2, llm.modelId);
58072
+ this.#modelInfos[key] = modelInfo;
58073
+ }
58074
+ } catch {
58075
+ modelInfo = {
58076
+ inputPrice: 0,
58077
+ outputPrice: 0,
58078
+ cacheWritesPrice: 0,
58079
+ cacheReadsPrice: 0
58080
+ };
58081
+ }
58082
+ modelInfo = modelInfo ?? {
58083
+ inputPrice: 0,
58084
+ outputPrice: 0,
58085
+ cacheWritesPrice: 0,
58086
+ cacheReadsPrice: 0
58087
+ };
58088
+ const usage = "totalUsage" in resp ? resp.totalUsage : resp.usage;
58089
+ const result = this.#calculateUsage(usage, resp.providerMetadata, modelInfo);
58090
+ this.#totals.input += result.input || 0;
58091
+ this.#totals.output += result.output || 0;
58092
+ this.#totals.cachedRead += result.cachedRead || 0;
58093
+ this.#totals.cost += result.cost || 0;
58094
+ this.#totals.messageCount += 1;
58095
+ if (resp.providerMetadata && Object.keys(resp.providerMetadata).length > 0) {
58096
+ const providerKey = Object.keys(resp.providerMetadata)[0];
58097
+ this.#providerMetadataEntries.push({
58098
+ provider: providerKey || llm.provider,
58099
+ model: llm.modelId,
58100
+ metadata: resp.providerMetadata[providerKey] || resp.providerMetadata,
58101
+ timestamp: Date.now()
58102
+ });
58103
+ }
58104
+ })();
58105
+ this.#pendingUpdates.add(updatePromise);
58106
+ updatePromise.finally(() => {
58107
+ this.#pendingUpdates.delete(updatePromise);
58108
+ });
58109
+ return updatePromise;
57910
58110
  }
57911
58111
  setUsage(newUsage, options = {}) {
57912
58112
  if (newUsage.input != null)
@@ -57990,13 +58190,17 @@ class UsageMeter {
57990
58190
  this.#totals.messageCount += otherUsage.messageCount;
57991
58191
  this.#providerMetadataEntries.push(...other.providerMetadata);
57992
58192
  }
58193
+ async waitForPending() {
58194
+ const pending = Array.from(this.#pendingUpdates);
58195
+ await Promise.allSettled(pending);
58196
+ }
57993
58197
  getUsageText() {
57994
58198
  const u = this.usage;
57995
58199
  return `Usage - messages: ${u.messageCount}, input: ${u.input}, cached: ${u.cachedRead}, output: ${u.output}, cost: $${u.cost.toFixed(4)}`;
57996
58200
  }
57997
58201
  onFinishHandler(llm) {
57998
- return (evt) => {
57999
- this.addUsage(llm, evt);
58202
+ return async (evt) => {
58203
+ await this.addUsage(llm, evt);
58000
58204
  };
58001
58205
  }
58002
58206
  }
@@ -68799,8 +69003,8 @@ var merge2 = _createAssigner_default(function(object3, source, srcIndex) {
68799
69003
  });
68800
69004
  var merge_default = merge2;
68801
69005
  // ../cli-shared/src/config.ts
68802
- function getGlobalConfigPath(home = homedir()) {
68803
- return join(home, ".config", "polkacodes", "config.yml");
69006
+ function getGlobalConfigPath(home = homedir2()) {
69007
+ return join2(home, ".config", "polkacodes", "config.yml");
68804
69008
  }
68805
69009
  var localConfigFileName = ".polkacodes.yml";
68806
69010
  var mergeArray = (a, b) => {
@@ -68878,7 +69082,7 @@ async function resolveRules(rules) {
68878
69082
  }
68879
69083
  } else if ("path" in rule) {
68880
69084
  if (existsSync(rule.path)) {
68881
- return await readFile(rule.path, "utf-8");
69085
+ return await readFile2(rule.path, "utf-8");
68882
69086
  }
68883
69087
  console.warn(`Rule file not found: ${rule.path}`);
68884
69088
  }
@@ -68888,7 +69092,7 @@ async function resolveRules(rules) {
68888
69092
 
68889
69093
  `);
68890
69094
  }
68891
- async function loadConfig(paths, cwd = process.cwd(), home = homedir()) {
69095
+ async function loadConfig(paths, cwd = process.cwd(), home = homedir2()) {
68892
69096
  const configs = [];
68893
69097
  const globalConfigPath = getGlobalConfigPath(home);
68894
69098
  if (existsSync(globalConfigPath)) {
@@ -68917,7 +69121,7 @@ ${error48}`);
68917
69121
  }
68918
69122
  }
68919
69123
  } else {
68920
- const configPath = join(cwd, localConfigFileName);
69124
+ const configPath = join2(cwd, localConfigFileName);
68921
69125
  try {
68922
69126
  const projectConfig = readConfig(configPath);
68923
69127
  configs.push(projectConfig);
@@ -68950,8 +69154,8 @@ var readConfig = (path) => {
68950
69154
  };
68951
69155
  // ../cli-shared/src/provider.ts
68952
69156
  import { spawn as spawn2 } from "node:child_process";
68953
- import { mkdir, readFile as readFile2, rename, unlink, writeFile } from "node:fs/promises";
68954
- import { dirname, normalize, resolve as resolve3 } from "node:path";
69157
+ import { mkdir as mkdir2, readFile as readFile3, rename as rename2, unlink, writeFile as writeFile2 } from "node:fs/promises";
69158
+ import { dirname as dirname2, normalize, resolve as resolve3 } from "node:path";
68955
69159
 
68956
69160
  // ../../node_modules/@ai-sdk/google-vertex/dist/index.mjs
68957
69161
  var import_google_auth_library = __toESM(require_src7(), 1);
@@ -72367,7 +72571,7 @@ function checkRipgrep() {
72367
72571
  // ../cli-shared/src/utils/listFiles.ts
72368
72572
  var import_ignore = __toESM(require_ignore(), 1);
72369
72573
  import { promises as fs3 } from "node:fs";
72370
- import { join as join2, relative, resolve as resolve2 } from "node:path";
72574
+ import { join as join3, relative, resolve as resolve2 } from "node:path";
72371
72575
  var DEFAULT_IGNORES = [
72372
72576
  "__pycache__",
72373
72577
  ".DS_Store",
@@ -72385,7 +72589,7 @@ var DEFAULT_IGNORES = [
72385
72589
  ];
72386
72590
  async function extendPatterns(basePatterns, dirPath) {
72387
72591
  try {
72388
- const gitignorePath = join2(dirPath, ".gitignore");
72592
+ const gitignorePath = join3(dirPath, ".gitignore");
72389
72593
  const content = await fs3.readFile(gitignorePath, "utf8");
72390
72594
  const lines = content.split(/\r?\n/).filter(Boolean);
72391
72595
  return [...basePatterns, ...lines];
@@ -72401,7 +72605,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
72401
72605
  if (!includeIgnored) {
72402
72606
  rootPatterns.push(...DEFAULT_IGNORES);
72403
72607
  try {
72404
- const rootGitignore = await fs3.readFile(join2(cwd, ".gitignore"), "utf8");
72608
+ const rootGitignore = await fs3.readFile(join3(cwd, ".gitignore"), "utf8");
72405
72609
  const lines = rootGitignore.split(/\r?\n/).filter(Boolean);
72406
72610
  rootPatterns = [...rootPatterns, ...lines];
72407
72611
  } catch {}
@@ -72423,7 +72627,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
72423
72627
  const entries = await fs3.readdir(currentPath, { withFileTypes: true });
72424
72628
  entries.sort((a, b) => a.name.localeCompare(b.name));
72425
72629
  for (const entry of entries) {
72426
- const fullPath = join2(currentPath, entry.name);
72630
+ const fullPath = join3(currentPath, entry.name);
72427
72631
  const relPath = relative(cwd, fullPath).replace(/\\/g, "/");
72428
72632
  if (folderIg.ignores(relPath)) {
72429
72633
  continue;
@@ -72440,7 +72644,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
72440
72644
  results.push(relPath);
72441
72645
  if (results.length >= maxCount) {
72442
72646
  const remainingEntries = entries.slice(entries.indexOf(entry) + 1);
72443
- const hasRemainingFiles = remainingEntries.some((e2) => !e2.isDirectory() && !folderIg.ignores(relative(cwd, join2(currentPath, e2.name)).replace(/\\/g, "/")));
72647
+ const hasRemainingFiles = remainingEntries.some((e2) => !e2.isDirectory() && !folderIg.ignores(relative(cwd, join3(currentPath, e2.name)).replace(/\\/g, "/")));
72444
72648
  if (hasRemainingFiles) {
72445
72649
  const marker16 = `${currentRelPath}/(files omitted)`;
72446
72650
  results.push(marker16);
@@ -72692,7 +72896,7 @@ ${content}`;
72692
72896
  throw new Error(`Not allow to access file ${path}`);
72693
72897
  }
72694
72898
  try {
72695
- return await readFile2(path, "utf8");
72899
+ return await readFile3(path, "utf8");
72696
72900
  } catch (_e) {
72697
72901
  return;
72698
72902
  }
@@ -72701,8 +72905,8 @@ ${content}`;
72701
72905
  if (ig.ignores(path)) {
72702
72906
  throw new Error(`Not allow to access file ${path}`);
72703
72907
  }
72704
- await mkdir(dirname(path), { recursive: true });
72705
- return await writeFile(path, content, "utf8");
72908
+ await mkdir2(dirname2(path), { recursive: true });
72909
+ return await writeFile2(path, content, "utf8");
72706
72910
  },
72707
72911
  removeFile: async (path) => {
72708
72912
  if (ig.ignores(path)) {
@@ -72714,7 +72918,7 @@ ${content}`;
72714
72918
  if (ig.ignores(sourcePath) || ig.ignores(targetPath)) {
72715
72919
  throw new Error(`Not allow to access file ${sourcePath} or ${targetPath}`);
72716
72920
  }
72717
- return await rename(sourcePath, targetPath);
72921
+ return await rename2(sourcePath, targetPath);
72718
72922
  },
72719
72923
  listFiles: async (path, recursive, maxCount, includeIgnored) => {
72720
72924
  return await listFiles(path, recursive, maxCount, process.cwd(), options.excludeFiles, includeIgnored);
@@ -72726,7 +72930,7 @@ ${content}`;
72726
72930
  if (!resolvedPath.startsWith(process.cwd())) {
72727
72931
  throw new Error(`Access to file path "${filePath}" is restricted.`);
72728
72932
  }
72729
- const data2 = await readFile2(resolvedPath);
72933
+ const data2 = await readFile3(resolvedPath);
72730
72934
  const mediaType2 = $lookup(resolvedPath) || "application/octet-stream";
72731
72935
  return {
72732
72936
  base64Data: data2.toString("base64"),
@@ -72854,10 +73058,10 @@ ${content}`;
72854
73058
  };
72855
73059
  // ../cli-shared/src/sqlite-memory-store.ts
72856
73060
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
72857
- import { randomUUID } from "node:crypto";
73061
+ import { randomUUID as randomUUID2 } from "node:crypto";
72858
73062
  import { existsSync as existsSync2 } from "node:fs";
72859
- import { mkdir as mkdir2, readdir, readFile as readFile3, rename as rename2, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
72860
- import { basename as basename2, dirname as dirname2, resolve as resolve4 } from "node:path";
73063
+ import { mkdir as mkdir3, readdir, readFile as readFile4, rename as rename3, unlink as unlink2, writeFile as writeFile3 } from "node:fs/promises";
73064
+ import { basename as basename2, dirname as dirname3, resolve as resolve4 } from "node:path";
72861
73065
  import { fileURLToPath } from "node:url";
72862
73066
  var import_sql = __toESM(require_sql_wasm(), 1);
72863
73067
 
@@ -72880,7 +73084,7 @@ class FileLock {
72880
73084
  }
72881
73085
  FileLock.lastCleanupTime = now;
72882
73086
  try {
72883
- const lockDir = dirname2(dbPath);
73087
+ const lockDir = dirname3(dbPath);
72884
73088
  const dbBaseName = basename2(dbPath);
72885
73089
  const files = await readdir(lockDir);
72886
73090
  const now2 = Date.now();
@@ -72917,7 +73121,7 @@ class FileLock {
72917
73121
  pid: process.pid,
72918
73122
  acquiredAt: Date.now()
72919
73123
  });
72920
- await writeFile2(this.lockfilePath, lockData, {
73124
+ await writeFile3(this.lockfilePath, lockData, {
72921
73125
  flag: "wx",
72922
73126
  mode: 384
72923
73127
  });
@@ -72926,23 +73130,23 @@ class FileLock {
72926
73130
  const errorCode = error48?.code;
72927
73131
  if (errorCode === "EEXIST") {
72928
73132
  try {
72929
- const lockContent = await readFile3(this.lockfilePath, "utf-8");
73133
+ const lockContent = await readFile4(this.lockfilePath, "utf-8");
72930
73134
  const lockData = JSON.parse(lockContent);
72931
73135
  if (!lockData || typeof lockData.acquiredAt !== "number" || lockData.acquiredAt <= 0) {
72932
73136
  console.warn(`[FileLock] Lock file has invalid acquiredAt, treating as stale`);
72933
- await rename2(this.lockfilePath, `${this.lockfilePath}.invalid.${Date.now()}`);
73137
+ await rename3(this.lockfilePath, `${this.lockfilePath}.invalid.${Date.now()}`);
72934
73138
  continue;
72935
73139
  }
72936
73140
  const lockAge = Date.now() - lockData.acquiredAt;
72937
73141
  if (lockAge > FileLock.LOCK_TIMEOUT) {
72938
73142
  console.warn(`[FileLock] Breaking stale lock (age: ${lockAge}ms)`);
72939
- await rename2(this.lockfilePath, `${this.lockfilePath}.stale.${Date.now()}`);
73143
+ await rename3(this.lockfilePath, `${this.lockfilePath}.stale.${Date.now()}`);
72940
73144
  continue;
72941
73145
  }
72942
73146
  } catch (readError) {
72943
73147
  if (readError instanceof SyntaxError) {
72944
73148
  console.warn(`[FileLock] Lock file contains invalid JSON, treating as stale`);
72945
- await rename2(this.lockfilePath, `${this.lockfilePath}.corrupt.${Date.now()}`);
73149
+ await rename3(this.lockfilePath, `${this.lockfilePath}.corrupt.${Date.now()}`);
72946
73150
  continue;
72947
73151
  }
72948
73152
  }
@@ -72959,7 +73163,7 @@ class FileLock {
72959
73163
  }
72960
73164
  async release() {
72961
73165
  try {
72962
- await rename2(this.lockfilePath, `${this.lockfilePath}.released.${Date.now()}`);
73166
+ await rename3(this.lockfilePath, `${this.lockfilePath}.released.${Date.now()}`);
72963
73167
  const dbPath = this.lockfilePath.slice(0, -5);
72964
73168
  FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
72965
73169
  } catch (error48) {
@@ -73013,7 +73217,7 @@ async function getSqlJs() {
73013
73217
  if (SqlJsInitPromise) {
73014
73218
  return SqlJsInitPromise;
73015
73219
  }
73016
- const moduleDir = dirname2(fileURLToPath(import.meta.url));
73220
+ const moduleDir = dirname3(fileURLToPath(import.meta.url));
73017
73221
  const candidates = [
73018
73222
  resolve4(moduleDir, "sql-wasm.wasm"),
73019
73223
  resolve4(moduleDir, "..", "dist", "sql-wasm.wasm"),
@@ -73079,9 +73283,9 @@ class SQLiteMemoryStore {
73079
73283
  }
73080
73284
  const dbPath = this.resolvePath(this.getDbPath());
73081
73285
  try {
73082
- const dir = dirname2(dbPath);
73286
+ const dir = dirname3(dbPath);
73083
73287
  if (!existsSync2(dir)) {
73084
- await mkdir2(dir, { recursive: true, mode: 448 });
73288
+ await mkdir3(dir, { recursive: true, mode: 448 });
73085
73289
  }
73086
73290
  FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
73087
73291
  let dbData;
@@ -73090,7 +73294,7 @@ class SQLiteMemoryStore {
73090
73294
  await lock.acquire();
73091
73295
  try {
73092
73296
  try {
73093
- dbData = await readFile3(dbPath);
73297
+ dbData = await readFile4(dbPath);
73094
73298
  if (dbData.length >= 16) {
73095
73299
  const header = String.fromCharCode(...dbData.subarray(0, 15));
73096
73300
  if (header !== "SQLite format 3") {
@@ -73123,7 +73327,7 @@ class SQLiteMemoryStore {
73123
73327
  const backupPath = `${dbPath}.corrupted.${Date.now()}`;
73124
73328
  console.warn(`[SQLiteMemoryStore] Backing up corrupted database to: ${backupPath}`);
73125
73329
  try {
73126
- await rename2(dbPath, backupPath);
73330
+ await rename3(dbPath, backupPath);
73127
73331
  } catch (backupError) {
73128
73332
  console.error("[SQLiteMemoryStore] Failed to backup corrupted database:", backupError);
73129
73333
  this.dbPromise = null;
@@ -73148,8 +73352,8 @@ class SQLiteMemoryStore {
73148
73352
  const dbPath = this.resolvePath(this.getDbPath());
73149
73353
  const tempPath = `${dbPath}.tmp`;
73150
73354
  const data = this.db.export();
73151
- await writeFile2(tempPath, data, { mode: 384 });
73152
- await rename2(tempPath, dbPath);
73355
+ await writeFile3(tempPath, data, { mode: 384 });
73356
+ await rename3(tempPath, dbPath);
73153
73357
  } finally {
73154
73358
  await lock.release();
73155
73359
  }
@@ -73203,7 +73407,7 @@ class SQLiteMemoryStore {
73203
73407
  return resolve4(resolved);
73204
73408
  }
73205
73409
  generateUUID() {
73206
- return randomUUID();
73410
+ return randomUUID2();
73207
73411
  }
73208
73412
  now() {
73209
73413
  return Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/runner",
3
- "version": "0.9.101",
3
+ "version": "0.9.102",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",