@polka-codes/runner 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 +278 -73
  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.100";
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}`,
@@ -56581,8 +56581,182 @@ var configSchema = exports_external.object({
56581
56581
  rules: exports_external.array(ruleSchema).optional().or(exports_external.string()).optional(),
56582
56582
  excludeFiles: exports_external.array(exports_external.string()).optional(),
56583
56583
  agent: agentSchema,
56584
- memory: memoryConfigSchema
56584
+ memory: memoryConfigSchema,
56585
+ loadRules: exports_external.record(exports_external.string(), exports_external.boolean()).optional()
56585
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
+ }
56586
56760
  // ../core/src/skills/constants.ts
56587
56761
  var SKILL_LIMITS = {
56588
56762
  MAX_FILE_SIZE: 1024 * 1024,
@@ -57816,9 +57990,11 @@ var writeToFile_default = {
57816
57990
  class UsageMeter {
57817
57991
  #totals = { input: 0, output: 0, cachedRead: 0, cost: 0, messageCount: 0 };
57818
57992
  #providerMetadataEntries = [];
57993
+ #pendingUpdates = new Set;
57819
57994
  #modelInfos;
57820
57995
  #maxMessages;
57821
57996
  #maxCost;
57997
+ #pricingService;
57822
57998
  constructor(modelInfos = {}, opts = {}) {
57823
57999
  const infos = {};
57824
58000
  for (const [provider2, providerInfo] of Object.entries(modelInfos)) {
@@ -57834,6 +58010,7 @@ class UsageMeter {
57834
58010
  this.#modelInfos = infos;
57835
58011
  this.#maxMessages = opts.maxMessages ?? 1000;
57836
58012
  this.#maxCost = opts.maxCost ?? 100;
58013
+ this.#pricingService = opts.pricingService;
57837
58014
  }
57838
58015
  #calculateUsage(usage, providerMetadata, modelInfo) {
57839
58016
  const providerMetadataKey = Object.keys(providerMetadata ?? {})[0];
@@ -57884,28 +58061,52 @@ class UsageMeter {
57884
58061
  }
57885
58062
  }
57886
58063
  addUsage(llm, resp, options = {}) {
57887
- const modelInfo = options.modelInfo ?? this.#modelInfos[`${llm.provider.split(".")[0]}:${llm.modelId.replace(/[.-]/g, "")}`] ?? {
57888
- inputPrice: 0,
57889
- outputPrice: 0,
57890
- cacheWritesPrice: 0,
57891
- cacheReadsPrice: 0
57892
- };
57893
- const usage = "totalUsage" in resp ? resp.totalUsage : resp.usage;
57894
- const result = this.#calculateUsage(usage, resp.providerMetadata, modelInfo);
57895
- this.#totals.input += result.input || 0;
57896
- this.#totals.output += result.output || 0;
57897
- this.#totals.cachedRead += result.cachedRead || 0;
57898
- this.#totals.cost += result.cost || 0;
57899
- this.#totals.messageCount += 1;
57900
- if (resp.providerMetadata && Object.keys(resp.providerMetadata).length > 0) {
57901
- const providerKey = Object.keys(resp.providerMetadata)[0];
57902
- this.#providerMetadataEntries.push({
57903
- provider: providerKey || llm.provider,
57904
- model: llm.modelId,
57905
- metadata: resp.providerMetadata[providerKey] || resp.providerMetadata,
57906
- timestamp: Date.now()
57907
- });
57908
- }
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;
57909
58110
  }
57910
58111
  setUsage(newUsage, options = {}) {
57911
58112
  if (newUsage.input != null)
@@ -57989,13 +58190,17 @@ class UsageMeter {
57989
58190
  this.#totals.messageCount += otherUsage.messageCount;
57990
58191
  this.#providerMetadataEntries.push(...other.providerMetadata);
57991
58192
  }
58193
+ async waitForPending() {
58194
+ const pending = Array.from(this.#pendingUpdates);
58195
+ await Promise.allSettled(pending);
58196
+ }
57992
58197
  getUsageText() {
57993
58198
  const u = this.usage;
57994
58199
  return `Usage - messages: ${u.messageCount}, input: ${u.input}, cached: ${u.cachedRead}, output: ${u.output}, cost: $${u.cost.toFixed(4)}`;
57995
58200
  }
57996
58201
  onFinishHandler(llm) {
57997
- return (evt) => {
57998
- this.addUsage(llm, evt);
58202
+ return async (evt) => {
58203
+ await this.addUsage(llm, evt);
57999
58204
  };
58000
58205
  }
58001
58206
  }
@@ -68798,8 +69003,8 @@ var merge2 = _createAssigner_default(function(object3, source, srcIndex) {
68798
69003
  });
68799
69004
  var merge_default = merge2;
68800
69005
  // ../cli-shared/src/config.ts
68801
- function getGlobalConfigPath(home = homedir()) {
68802
- return join(home, ".config", "polkacodes", "config.yml");
69006
+ function getGlobalConfigPath(home = homedir2()) {
69007
+ return join2(home, ".config", "polkacodes", "config.yml");
68803
69008
  }
68804
69009
  var localConfigFileName = ".polkacodes.yml";
68805
69010
  var mergeArray = (a, b) => {
@@ -68877,7 +69082,7 @@ async function resolveRules(rules) {
68877
69082
  }
68878
69083
  } else if ("path" in rule) {
68879
69084
  if (existsSync(rule.path)) {
68880
- return await readFile(rule.path, "utf-8");
69085
+ return await readFile2(rule.path, "utf-8");
68881
69086
  }
68882
69087
  console.warn(`Rule file not found: ${rule.path}`);
68883
69088
  }
@@ -68887,7 +69092,7 @@ async function resolveRules(rules) {
68887
69092
 
68888
69093
  `);
68889
69094
  }
68890
- async function loadConfig(paths, cwd = process.cwd(), home = homedir()) {
69095
+ async function loadConfig(paths, cwd = process.cwd(), home = homedir2()) {
68891
69096
  const configs = [];
68892
69097
  const globalConfigPath = getGlobalConfigPath(home);
68893
69098
  if (existsSync(globalConfigPath)) {
@@ -68916,7 +69121,7 @@ ${error48}`);
68916
69121
  }
68917
69122
  }
68918
69123
  } else {
68919
- const configPath = join(cwd, localConfigFileName);
69124
+ const configPath = join2(cwd, localConfigFileName);
68920
69125
  try {
68921
69126
  const projectConfig = readConfig(configPath);
68922
69127
  configs.push(projectConfig);
@@ -68949,8 +69154,8 @@ var readConfig = (path) => {
68949
69154
  };
68950
69155
  // ../cli-shared/src/provider.ts
68951
69156
  import { spawn as spawn2 } from "node:child_process";
68952
- import { mkdir, readFile as readFile2, rename, unlink, writeFile } from "node:fs/promises";
68953
- 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";
68954
69159
 
68955
69160
  // ../../node_modules/@ai-sdk/google-vertex/dist/index.mjs
68956
69161
  var import_google_auth_library = __toESM(require_src7(), 1);
@@ -72366,7 +72571,7 @@ function checkRipgrep() {
72366
72571
  // ../cli-shared/src/utils/listFiles.ts
72367
72572
  var import_ignore = __toESM(require_ignore(), 1);
72368
72573
  import { promises as fs3 } from "node:fs";
72369
- import { join as join2, relative, resolve as resolve2 } from "node:path";
72574
+ import { join as join3, relative, resolve as resolve2 } from "node:path";
72370
72575
  var DEFAULT_IGNORES = [
72371
72576
  "__pycache__",
72372
72577
  ".DS_Store",
@@ -72384,7 +72589,7 @@ var DEFAULT_IGNORES = [
72384
72589
  ];
72385
72590
  async function extendPatterns(basePatterns, dirPath) {
72386
72591
  try {
72387
- const gitignorePath = join2(dirPath, ".gitignore");
72592
+ const gitignorePath = join3(dirPath, ".gitignore");
72388
72593
  const content = await fs3.readFile(gitignorePath, "utf8");
72389
72594
  const lines = content.split(/\r?\n/).filter(Boolean);
72390
72595
  return [...basePatterns, ...lines];
@@ -72400,7 +72605,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
72400
72605
  if (!includeIgnored) {
72401
72606
  rootPatterns.push(...DEFAULT_IGNORES);
72402
72607
  try {
72403
- const rootGitignore = await fs3.readFile(join2(cwd, ".gitignore"), "utf8");
72608
+ const rootGitignore = await fs3.readFile(join3(cwd, ".gitignore"), "utf8");
72404
72609
  const lines = rootGitignore.split(/\r?\n/).filter(Boolean);
72405
72610
  rootPatterns = [...rootPatterns, ...lines];
72406
72611
  } catch {}
@@ -72422,7 +72627,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
72422
72627
  const entries = await fs3.readdir(currentPath, { withFileTypes: true });
72423
72628
  entries.sort((a, b) => a.name.localeCompare(b.name));
72424
72629
  for (const entry of entries) {
72425
- const fullPath = join2(currentPath, entry.name);
72630
+ const fullPath = join3(currentPath, entry.name);
72426
72631
  const relPath = relative(cwd, fullPath).replace(/\\/g, "/");
72427
72632
  if (folderIg.ignores(relPath)) {
72428
72633
  continue;
@@ -72439,7 +72644,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
72439
72644
  results.push(relPath);
72440
72645
  if (results.length >= maxCount) {
72441
72646
  const remainingEntries = entries.slice(entries.indexOf(entry) + 1);
72442
- 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, "/")));
72443
72648
  if (hasRemainingFiles) {
72444
72649
  const marker16 = `${currentRelPath}/(files omitted)`;
72445
72650
  results.push(marker16);
@@ -72691,7 +72896,7 @@ ${content}`;
72691
72896
  throw new Error(`Not allow to access file ${path}`);
72692
72897
  }
72693
72898
  try {
72694
- return await readFile2(path, "utf8");
72899
+ return await readFile3(path, "utf8");
72695
72900
  } catch (_e) {
72696
72901
  return;
72697
72902
  }
@@ -72700,8 +72905,8 @@ ${content}`;
72700
72905
  if (ig.ignores(path)) {
72701
72906
  throw new Error(`Not allow to access file ${path}`);
72702
72907
  }
72703
- await mkdir(dirname(path), { recursive: true });
72704
- return await writeFile(path, content, "utf8");
72908
+ await mkdir2(dirname2(path), { recursive: true });
72909
+ return await writeFile2(path, content, "utf8");
72705
72910
  },
72706
72911
  removeFile: async (path) => {
72707
72912
  if (ig.ignores(path)) {
@@ -72713,7 +72918,7 @@ ${content}`;
72713
72918
  if (ig.ignores(sourcePath) || ig.ignores(targetPath)) {
72714
72919
  throw new Error(`Not allow to access file ${sourcePath} or ${targetPath}`);
72715
72920
  }
72716
- return await rename(sourcePath, targetPath);
72921
+ return await rename2(sourcePath, targetPath);
72717
72922
  },
72718
72923
  listFiles: async (path, recursive, maxCount, includeIgnored) => {
72719
72924
  return await listFiles(path, recursive, maxCount, process.cwd(), options.excludeFiles, includeIgnored);
@@ -72725,7 +72930,7 @@ ${content}`;
72725
72930
  if (!resolvedPath.startsWith(process.cwd())) {
72726
72931
  throw new Error(`Access to file path "${filePath}" is restricted.`);
72727
72932
  }
72728
- const data2 = await readFile2(resolvedPath);
72933
+ const data2 = await readFile3(resolvedPath);
72729
72934
  const mediaType2 = $lookup(resolvedPath) || "application/octet-stream";
72730
72935
  return {
72731
72936
  base64Data: data2.toString("base64"),
@@ -72853,10 +73058,10 @@ ${content}`;
72853
73058
  };
72854
73059
  // ../cli-shared/src/sqlite-memory-store.ts
72855
73060
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
72856
- import { randomUUID } from "node:crypto";
73061
+ import { randomUUID as randomUUID2 } from "node:crypto";
72857
73062
  import { existsSync as existsSync2 } from "node:fs";
72858
- import { mkdir as mkdir2, readdir, readFile as readFile3, rename as rename2, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
72859
- 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";
72860
73065
  import { fileURLToPath } from "node:url";
72861
73066
  var import_sql = __toESM(require_sql_wasm(), 1);
72862
73067
 
@@ -72879,7 +73084,7 @@ class FileLock {
72879
73084
  }
72880
73085
  FileLock.lastCleanupTime = now;
72881
73086
  try {
72882
- const lockDir = dirname2(dbPath);
73087
+ const lockDir = dirname3(dbPath);
72883
73088
  const dbBaseName = basename2(dbPath);
72884
73089
  const files = await readdir(lockDir);
72885
73090
  const now2 = Date.now();
@@ -72916,7 +73121,7 @@ class FileLock {
72916
73121
  pid: process.pid,
72917
73122
  acquiredAt: Date.now()
72918
73123
  });
72919
- await writeFile2(this.lockfilePath, lockData, {
73124
+ await writeFile3(this.lockfilePath, lockData, {
72920
73125
  flag: "wx",
72921
73126
  mode: 384
72922
73127
  });
@@ -72925,23 +73130,23 @@ class FileLock {
72925
73130
  const errorCode = error48?.code;
72926
73131
  if (errorCode === "EEXIST") {
72927
73132
  try {
72928
- const lockContent = await readFile3(this.lockfilePath, "utf-8");
73133
+ const lockContent = await readFile4(this.lockfilePath, "utf-8");
72929
73134
  const lockData = JSON.parse(lockContent);
72930
73135
  if (!lockData || typeof lockData.acquiredAt !== "number" || lockData.acquiredAt <= 0) {
72931
73136
  console.warn(`[FileLock] Lock file has invalid acquiredAt, treating as stale`);
72932
- await rename2(this.lockfilePath, `${this.lockfilePath}.invalid.${Date.now()}`);
73137
+ await rename3(this.lockfilePath, `${this.lockfilePath}.invalid.${Date.now()}`);
72933
73138
  continue;
72934
73139
  }
72935
73140
  const lockAge = Date.now() - lockData.acquiredAt;
72936
73141
  if (lockAge > FileLock.LOCK_TIMEOUT) {
72937
73142
  console.warn(`[FileLock] Breaking stale lock (age: ${lockAge}ms)`);
72938
- await rename2(this.lockfilePath, `${this.lockfilePath}.stale.${Date.now()}`);
73143
+ await rename3(this.lockfilePath, `${this.lockfilePath}.stale.${Date.now()}`);
72939
73144
  continue;
72940
73145
  }
72941
73146
  } catch (readError) {
72942
73147
  if (readError instanceof SyntaxError) {
72943
73148
  console.warn(`[FileLock] Lock file contains invalid JSON, treating as stale`);
72944
- await rename2(this.lockfilePath, `${this.lockfilePath}.corrupt.${Date.now()}`);
73149
+ await rename3(this.lockfilePath, `${this.lockfilePath}.corrupt.${Date.now()}`);
72945
73150
  continue;
72946
73151
  }
72947
73152
  }
@@ -72958,7 +73163,7 @@ class FileLock {
72958
73163
  }
72959
73164
  async release() {
72960
73165
  try {
72961
- await rename2(this.lockfilePath, `${this.lockfilePath}.released.${Date.now()}`);
73166
+ await rename3(this.lockfilePath, `${this.lockfilePath}.released.${Date.now()}`);
72962
73167
  const dbPath = this.lockfilePath.slice(0, -5);
72963
73168
  FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
72964
73169
  } catch (error48) {
@@ -73012,7 +73217,7 @@ async function getSqlJs() {
73012
73217
  if (SqlJsInitPromise) {
73013
73218
  return SqlJsInitPromise;
73014
73219
  }
73015
- const moduleDir = dirname2(fileURLToPath(import.meta.url));
73220
+ const moduleDir = dirname3(fileURLToPath(import.meta.url));
73016
73221
  const candidates = [
73017
73222
  resolve4(moduleDir, "sql-wasm.wasm"),
73018
73223
  resolve4(moduleDir, "..", "dist", "sql-wasm.wasm"),
@@ -73078,9 +73283,9 @@ class SQLiteMemoryStore {
73078
73283
  }
73079
73284
  const dbPath = this.resolvePath(this.getDbPath());
73080
73285
  try {
73081
- const dir = dirname2(dbPath);
73286
+ const dir = dirname3(dbPath);
73082
73287
  if (!existsSync2(dir)) {
73083
- await mkdir2(dir, { recursive: true, mode: 448 });
73288
+ await mkdir3(dir, { recursive: true, mode: 448 });
73084
73289
  }
73085
73290
  FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
73086
73291
  let dbData;
@@ -73089,7 +73294,7 @@ class SQLiteMemoryStore {
73089
73294
  await lock.acquire();
73090
73295
  try {
73091
73296
  try {
73092
- dbData = await readFile3(dbPath);
73297
+ dbData = await readFile4(dbPath);
73093
73298
  if (dbData.length >= 16) {
73094
73299
  const header = String.fromCharCode(...dbData.subarray(0, 15));
73095
73300
  if (header !== "SQLite format 3") {
@@ -73122,7 +73327,7 @@ class SQLiteMemoryStore {
73122
73327
  const backupPath = `${dbPath}.corrupted.${Date.now()}`;
73123
73328
  console.warn(`[SQLiteMemoryStore] Backing up corrupted database to: ${backupPath}`);
73124
73329
  try {
73125
- await rename2(dbPath, backupPath);
73330
+ await rename3(dbPath, backupPath);
73126
73331
  } catch (backupError) {
73127
73332
  console.error("[SQLiteMemoryStore] Failed to backup corrupted database:", backupError);
73128
73333
  this.dbPromise = null;
@@ -73147,8 +73352,8 @@ class SQLiteMemoryStore {
73147
73352
  const dbPath = this.resolvePath(this.getDbPath());
73148
73353
  const tempPath = `${dbPath}.tmp`;
73149
73354
  const data = this.db.export();
73150
- await writeFile2(tempPath, data, { mode: 384 });
73151
- await rename2(tempPath, dbPath);
73355
+ await writeFile3(tempPath, data, { mode: 384 });
73356
+ await rename3(tempPath, dbPath);
73152
73357
  } finally {
73153
73358
  await lock.release();
73154
73359
  }
@@ -73202,7 +73407,7 @@ class SQLiteMemoryStore {
73202
73407
  return resolve4(resolved);
73203
73408
  }
73204
73409
  generateUUID() {
73205
- return randomUUID();
73410
+ return randomUUID2();
73206
73411
  }
73207
73412
  now() {
73208
73413
  return Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/runner",
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",