@polka-codes/cli-shared 0.9.0 → 0.9.2

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 +664 -654
  2. package/package.json +5 -3
package/dist/index.js CHANGED
@@ -13741,333 +13741,6 @@ var require_public_api = __commonJS((exports) => {
13741
13741
  exports.stringify = stringify;
13742
13742
  });
13743
13743
 
13744
- // ../../node_modules/ignore/index.js
13745
- var require_ignore = __commonJS((exports, module) => {
13746
- function makeArray(subject) {
13747
- return Array.isArray(subject) ? subject : [subject];
13748
- }
13749
- var UNDEFINED = undefined;
13750
- var EMPTY = "";
13751
- var SPACE = " ";
13752
- var ESCAPE = "\\";
13753
- var REGEX_TEST_BLANK_LINE = /^\s+$/;
13754
- var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
13755
- var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
13756
- var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
13757
- var REGEX_SPLITALL_CRLF = /\r?\n/g;
13758
- var REGEX_TEST_INVALID_PATH = /^\.{0,2}\/|^\.{1,2}$/;
13759
- var REGEX_TEST_TRAILING_SLASH = /\/$/;
13760
- var SLASH = "/";
13761
- var TMP_KEY_IGNORE = "node-ignore";
13762
- if (typeof Symbol !== "undefined") {
13763
- TMP_KEY_IGNORE = Symbol.for("node-ignore");
13764
- }
13765
- var KEY_IGNORE = TMP_KEY_IGNORE;
13766
- var define2 = (object5, key, value) => {
13767
- Object.defineProperty(object5, key, { value });
13768
- return value;
13769
- };
13770
- var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
13771
- var RETURN_FALSE = () => false;
13772
- var sanitizeRange = (range) => range.replace(REGEX_REGEXP_RANGE, (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0) ? match : EMPTY);
13773
- var cleanRangeBackSlash = (slashes) => {
13774
- const { length } = slashes;
13775
- return slashes.slice(0, length - length % 2);
13776
- };
13777
- var REPLACERS = [
13778
- [
13779
- /^\uFEFF/,
13780
- () => EMPTY
13781
- ],
13782
- [
13783
- /((?:\\\\)*?)(\\?\s+)$/,
13784
- (_, m1, m2) => m1 + (m2.indexOf("\\") === 0 ? SPACE : EMPTY)
13785
- ],
13786
- [
13787
- /(\\+?)\s/g,
13788
- (_, m1) => {
13789
- const { length } = m1;
13790
- return m1.slice(0, length - length % 2) + SPACE;
13791
- }
13792
- ],
13793
- [
13794
- /[\\$.|*+(){^]/g,
13795
- (match) => `\\${match}`
13796
- ],
13797
- [
13798
- /(?!\\)\?/g,
13799
- () => "[^/]"
13800
- ],
13801
- [
13802
- /^\//,
13803
- () => "^"
13804
- ],
13805
- [
13806
- /\//g,
13807
- () => "\\/"
13808
- ],
13809
- [
13810
- /^\^*\\\*\\\*\\\//,
13811
- () => "^(?:.*\\/)?"
13812
- ],
13813
- [
13814
- /^(?=[^^])/,
13815
- function startingReplacer() {
13816
- return !/\/(?!$)/.test(this) ? "(?:^|\\/)" : "^";
13817
- }
13818
- ],
13819
- [
13820
- /\\\/\\\*\\\*(?=\\\/|$)/g,
13821
- (_, index, str) => index + 6 < str.length ? "(?:\\/[^\\/]+)*" : "\\/.+"
13822
- ],
13823
- [
13824
- /(^|[^\\]+)(\\\*)+(?=.+)/g,
13825
- (_, p1, p2) => {
13826
- const unescaped = p2.replace(/\\\*/g, "[^\\/]*");
13827
- return p1 + unescaped;
13828
- }
13829
- ],
13830
- [
13831
- /\\\\\\(?=[$.|*+(){^])/g,
13832
- () => ESCAPE
13833
- ],
13834
- [
13835
- /\\\\/g,
13836
- () => ESCAPE
13837
- ],
13838
- [
13839
- /(\\)?\[([^\]/]*?)(\\*)($|\])/g,
13840
- (match, leadEscape, range, endEscape, close) => leadEscape === ESCAPE ? `\\[${range}${cleanRangeBackSlash(endEscape)}${close}` : close === "]" ? endEscape.length % 2 === 0 ? `[${sanitizeRange(range)}${endEscape}]` : "[]" : "[]"
13841
- ],
13842
- [
13843
- /(?:[^*])$/,
13844
- (match) => /\/$/.test(match) ? `${match}$` : `${match}(?=$|\\/$)`
13845
- ]
13846
- ];
13847
- var REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\\\*$/;
13848
- var MODE_IGNORE = "regex";
13849
- var MODE_CHECK_IGNORE = "checkRegex";
13850
- var UNDERSCORE = "_";
13851
- var TRAILING_WILD_CARD_REPLACERS = {
13852
- [MODE_IGNORE](_, p1) {
13853
- const prefix = p1 ? `${p1}[^/]+` : "[^/]*";
13854
- return `${prefix}(?=$|\\/$)`;
13855
- },
13856
- [MODE_CHECK_IGNORE](_, p1) {
13857
- const prefix = p1 ? `${p1}[^/]*` : "[^/]*";
13858
- return `${prefix}(?=$|\\/$)`;
13859
- }
13860
- };
13861
- var makeRegexPrefix = (pattern) => REPLACERS.reduce((prev, [matcher, replacer]) => prev.replace(matcher, replacer.bind(pattern)), pattern);
13862
- var isString = (subject) => typeof subject === "string";
13863
- var checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) && pattern.indexOf("#") !== 0;
13864
- var splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
13865
-
13866
- class IgnoreRule {
13867
- constructor(pattern, mark, body, ignoreCase, negative, prefix) {
13868
- this.pattern = pattern;
13869
- this.mark = mark;
13870
- this.negative = negative;
13871
- define2(this, "body", body);
13872
- define2(this, "ignoreCase", ignoreCase);
13873
- define2(this, "regexPrefix", prefix);
13874
- }
13875
- get regex() {
13876
- const key = UNDERSCORE + MODE_IGNORE;
13877
- if (this[key]) {
13878
- return this[key];
13879
- }
13880
- return this._make(MODE_IGNORE, key);
13881
- }
13882
- get checkRegex() {
13883
- const key = UNDERSCORE + MODE_CHECK_IGNORE;
13884
- if (this[key]) {
13885
- return this[key];
13886
- }
13887
- return this._make(MODE_CHECK_IGNORE, key);
13888
- }
13889
- _make(mode, key) {
13890
- const str = this.regexPrefix.replace(REGEX_REPLACE_TRAILING_WILDCARD, TRAILING_WILD_CARD_REPLACERS[mode]);
13891
- const regex = this.ignoreCase ? new RegExp(str, "i") : new RegExp(str);
13892
- return define2(this, key, regex);
13893
- }
13894
- }
13895
- var createRule = ({
13896
- pattern,
13897
- mark
13898
- }, ignoreCase) => {
13899
- let negative = false;
13900
- let body = pattern;
13901
- if (body.indexOf("!") === 0) {
13902
- negative = true;
13903
- body = body.substr(1);
13904
- }
13905
- body = body.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, "!").replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, "#");
13906
- const regexPrefix = makeRegexPrefix(body);
13907
- return new IgnoreRule(pattern, mark, body, ignoreCase, negative, regexPrefix);
13908
- };
13909
-
13910
- class RuleManager {
13911
- constructor(ignoreCase) {
13912
- this._ignoreCase = ignoreCase;
13913
- this._rules = [];
13914
- }
13915
- _add(pattern) {
13916
- if (pattern && pattern[KEY_IGNORE]) {
13917
- this._rules = this._rules.concat(pattern._rules._rules);
13918
- this._added = true;
13919
- return;
13920
- }
13921
- if (isString(pattern)) {
13922
- pattern = {
13923
- pattern
13924
- };
13925
- }
13926
- if (checkPattern(pattern.pattern)) {
13927
- const rule = createRule(pattern, this._ignoreCase);
13928
- this._added = true;
13929
- this._rules.push(rule);
13930
- }
13931
- }
13932
- add(pattern) {
13933
- this._added = false;
13934
- makeArray(isString(pattern) ? splitPattern(pattern) : pattern).forEach(this._add, this);
13935
- return this._added;
13936
- }
13937
- test(path, checkUnignored, mode) {
13938
- let ignored = false;
13939
- let unignored = false;
13940
- let matchedRule;
13941
- this._rules.forEach((rule) => {
13942
- const { negative } = rule;
13943
- if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
13944
- return;
13945
- }
13946
- const matched = rule[mode].test(path);
13947
- if (!matched) {
13948
- return;
13949
- }
13950
- ignored = !negative;
13951
- unignored = negative;
13952
- matchedRule = negative ? UNDEFINED : rule;
13953
- });
13954
- const ret = {
13955
- ignored,
13956
- unignored
13957
- };
13958
- if (matchedRule) {
13959
- ret.rule = matchedRule;
13960
- }
13961
- return ret;
13962
- }
13963
- }
13964
- var throwError = (message, Ctor) => {
13965
- throw new Ctor(message);
13966
- };
13967
- var checkPath = (path, originalPath, doThrow) => {
13968
- if (!isString(path)) {
13969
- return doThrow(`path must be a string, but got \`${originalPath}\``, TypeError);
13970
- }
13971
- if (!path) {
13972
- return doThrow(`path must not be empty`, TypeError);
13973
- }
13974
- if (checkPath.isNotRelative(path)) {
13975
- const r = "`path.relative()`d";
13976
- return doThrow(`path should be a ${r} string, but got "${originalPath}"`, RangeError);
13977
- }
13978
- return true;
13979
- };
13980
- var isNotRelative = (path) => REGEX_TEST_INVALID_PATH.test(path);
13981
- checkPath.isNotRelative = isNotRelative;
13982
- checkPath.convert = (p) => p;
13983
-
13984
- class Ignore {
13985
- constructor({
13986
- ignorecase = true,
13987
- ignoreCase = ignorecase,
13988
- allowRelativePaths = false
13989
- } = {}) {
13990
- define2(this, KEY_IGNORE, true);
13991
- this._rules = new RuleManager(ignoreCase);
13992
- this._strictPathCheck = !allowRelativePaths;
13993
- this._initCache();
13994
- }
13995
- _initCache() {
13996
- this._ignoreCache = Object.create(null);
13997
- this._testCache = Object.create(null);
13998
- }
13999
- add(pattern) {
14000
- if (this._rules.add(pattern)) {
14001
- this._initCache();
14002
- }
14003
- return this;
14004
- }
14005
- addPattern(pattern) {
14006
- return this.add(pattern);
14007
- }
14008
- _test(originalPath, cache, checkUnignored, slices) {
14009
- const path = originalPath && checkPath.convert(originalPath);
14010
- checkPath(path, originalPath, this._strictPathCheck ? throwError : RETURN_FALSE);
14011
- return this._t(path, cache, checkUnignored, slices);
14012
- }
14013
- checkIgnore(path) {
14014
- if (!REGEX_TEST_TRAILING_SLASH.test(path)) {
14015
- return this.test(path);
14016
- }
14017
- const slices = path.split(SLASH).filter(Boolean);
14018
- slices.pop();
14019
- if (slices.length) {
14020
- const parent = this._t(slices.join(SLASH) + SLASH, this._testCache, true, slices);
14021
- if (parent.ignored) {
14022
- return parent;
14023
- }
14024
- }
14025
- return this._rules.test(path, false, MODE_CHECK_IGNORE);
14026
- }
14027
- _t(path, cache, checkUnignored, slices) {
14028
- if (path in cache) {
14029
- return cache[path];
14030
- }
14031
- if (!slices) {
14032
- slices = path.split(SLASH).filter(Boolean);
14033
- }
14034
- slices.pop();
14035
- if (!slices.length) {
14036
- return cache[path] = this._rules.test(path, checkUnignored, MODE_IGNORE);
14037
- }
14038
- const parent = this._t(slices.join(SLASH) + SLASH, cache, checkUnignored, slices);
14039
- return cache[path] = parent.ignored ? parent : this._rules.test(path, checkUnignored, MODE_IGNORE);
14040
- }
14041
- ignores(path) {
14042
- return this._test(path, this._ignoreCache, false).ignored;
14043
- }
14044
- createFilter() {
14045
- return (path) => !this.ignores(path);
14046
- }
14047
- filter(paths) {
14048
- return makeArray(paths).filter(this.createFilter());
14049
- }
14050
- test(path) {
14051
- return this._test(path, this._testCache, true);
14052
- }
14053
- }
14054
- var factory = (options) => new Ignore(options);
14055
- var isPathValid = (path) => checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
14056
- var setupWindows = () => {
14057
- const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
14058
- checkPath.convert = makePosix;
14059
- const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
14060
- checkPath.isNotRelative = (path) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
14061
- };
14062
- if (typeof process !== "undefined" && process.platform === "win32") {
14063
- setupWindows();
14064
- }
14065
- module.exports = factory;
14066
- factory.default = factory;
14067
- module.exports.isPathValid = isPathValid;
14068
- define2(module.exports, Symbol.for("setupWindows"), setupWindows);
14069
- });
14070
-
14071
13744
  // ../../node_modules/yoctocolors-cjs/index.js
14072
13745
  var require_yoctocolors_cjs = __commonJS((exports, module) => {
14073
13746
  var tty = __require("node:tty");
@@ -15711,142 +15384,338 @@ var require_ansi_escapes = __commonJS((exports, module) => {
15711
15384
  };
15712
15385
  });
15713
15386
 
15714
- // src/config.ts
15715
- import { existsSync, readFileSync } from "node:fs";
15716
- import { homedir } from "node:os";
15717
- import { join } from "node:path";
15387
+ // ../../node_modules/ignore/index.js
15388
+ var require_ignore = __commonJS((exports, module) => {
15389
+ function makeArray(subject) {
15390
+ return Array.isArray(subject) ? subject : [subject];
15391
+ }
15392
+ var UNDEFINED = undefined;
15393
+ var EMPTY = "";
15394
+ var SPACE = " ";
15395
+ var ESCAPE = "\\";
15396
+ var REGEX_TEST_BLANK_LINE = /^\s+$/;
15397
+ var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
15398
+ var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
15399
+ var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
15400
+ var REGEX_SPLITALL_CRLF = /\r?\n/g;
15401
+ var REGEX_TEST_INVALID_PATH = /^\.{0,2}\/|^\.{1,2}$/;
15402
+ var REGEX_TEST_TRAILING_SLASH = /\/$/;
15403
+ var SLASH = "/";
15404
+ var TMP_KEY_IGNORE = "node-ignore";
15405
+ if (typeof Symbol !== "undefined") {
15406
+ TMP_KEY_IGNORE = Symbol.for("node-ignore");
15407
+ }
15408
+ var KEY_IGNORE = TMP_KEY_IGNORE;
15409
+ var define2 = (object5, key2, value) => {
15410
+ Object.defineProperty(object5, key2, { value });
15411
+ return value;
15412
+ };
15413
+ var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
15414
+ var RETURN_FALSE = () => false;
15415
+ var sanitizeRange = (range) => range.replace(REGEX_REGEXP_RANGE, (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0) ? match : EMPTY);
15416
+ var cleanRangeBackSlash = (slashes) => {
15417
+ const { length } = slashes;
15418
+ return slashes.slice(0, length - length % 2);
15419
+ };
15420
+ var REPLACERS = [
15421
+ [
15422
+ /^\uFEFF/,
15423
+ () => EMPTY
15424
+ ],
15425
+ [
15426
+ /((?:\\\\)*?)(\\?\s+)$/,
15427
+ (_, m1, m2) => m1 + (m2.indexOf("\\") === 0 ? SPACE : EMPTY)
15428
+ ],
15429
+ [
15430
+ /(\\+?)\s/g,
15431
+ (_, m1) => {
15432
+ const { length } = m1;
15433
+ return m1.slice(0, length - length % 2) + SPACE;
15434
+ }
15435
+ ],
15436
+ [
15437
+ /[\\$.|*+(){^]/g,
15438
+ (match) => `\\${match}`
15439
+ ],
15440
+ [
15441
+ /(?!\\)\?/g,
15442
+ () => "[^/]"
15443
+ ],
15444
+ [
15445
+ /^\//,
15446
+ () => "^"
15447
+ ],
15448
+ [
15449
+ /\//g,
15450
+ () => "\\/"
15451
+ ],
15452
+ [
15453
+ /^\^*\\\*\\\*\\\//,
15454
+ () => "^(?:.*\\/)?"
15455
+ ],
15456
+ [
15457
+ /^(?=[^^])/,
15458
+ function startingReplacer() {
15459
+ return !/\/(?!$)/.test(this) ? "(?:^|\\/)" : "^";
15460
+ }
15461
+ ],
15462
+ [
15463
+ /\\\/\\\*\\\*(?=\\\/|$)/g,
15464
+ (_, index, str) => index + 6 < str.length ? "(?:\\/[^\\/]+)*" : "\\/.+"
15465
+ ],
15466
+ [
15467
+ /(^|[^\\]+)(\\\*)+(?=.+)/g,
15468
+ (_, p1, p2) => {
15469
+ const unescaped = p2.replace(/\\\*/g, "[^\\/]*");
15470
+ return p1 + unescaped;
15471
+ }
15472
+ ],
15473
+ [
15474
+ /\\\\\\(?=[$.|*+(){^])/g,
15475
+ () => ESCAPE
15476
+ ],
15477
+ [
15478
+ /\\\\/g,
15479
+ () => ESCAPE
15480
+ ],
15481
+ [
15482
+ /(\\)?\[([^\]/]*?)(\\*)($|\])/g,
15483
+ (match, leadEscape, range, endEscape, close) => leadEscape === ESCAPE ? `\\[${range}${cleanRangeBackSlash(endEscape)}${close}` : close === "]" ? endEscape.length % 2 === 0 ? `[${sanitizeRange(range)}${endEscape}]` : "[]" : "[]"
15484
+ ],
15485
+ [
15486
+ /(?:[^*])$/,
15487
+ (match) => /\/$/.test(match) ? `${match}$` : `${match}(?=$|\\/$)`
15488
+ ]
15489
+ ];
15490
+ var REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\\\*$/;
15491
+ var MODE_IGNORE = "regex";
15492
+ var MODE_CHECK_IGNORE = "checkRegex";
15493
+ var UNDERSCORE = "_";
15494
+ var TRAILING_WILD_CARD_REPLACERS = {
15495
+ [MODE_IGNORE](_, p1) {
15496
+ const prefix = p1 ? `${p1}[^/]+` : "[^/]*";
15497
+ return `${prefix}(?=$|\\/$)`;
15498
+ },
15499
+ [MODE_CHECK_IGNORE](_, p1) {
15500
+ const prefix = p1 ? `${p1}[^/]*` : "[^/]*";
15501
+ return `${prefix}(?=$|\\/$)`;
15502
+ }
15503
+ };
15504
+ var makeRegexPrefix = (pattern) => REPLACERS.reduce((prev, [matcher, replacer]) => prev.replace(matcher, replacer.bind(pattern)), pattern);
15505
+ var isString = (subject) => typeof subject === "string";
15506
+ var checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) && pattern.indexOf("#") !== 0;
15507
+ var splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
15718
15508
 
15719
- // ../core/src/UsageMeter.ts
15720
- class UsageMeter {
15721
- #totals = { input: 0, output: 0, cachedRead: 0, cost: 0 };
15722
- #calls = 0;
15723
- #modelInfos;
15724
- #maxMessages;
15725
- #maxCost;
15726
- constructor(modelInfos = {}, opts = {}) {
15727
- const infos = {};
15728
- for (const [provider, providerInfo] of Object.entries(modelInfos)) {
15729
- for (const [model, modelInfo] of Object.entries(providerInfo)) {
15730
- infos[`${provider.split("-")[0]}:${model.replace(/[\.-]/g, "")}`] = {
15731
- inputPrice: modelInfo.inputPrice ?? 0,
15732
- outputPrice: modelInfo.outputPrice ?? 0,
15733
- cacheWritesPrice: modelInfo.cacheWritesPrice ?? 0,
15734
- cacheReadsPrice: modelInfo.cacheReadsPrice ?? 0
15735
- };
15509
+ class IgnoreRule {
15510
+ constructor(pattern, mark, body, ignoreCase, negative, prefix) {
15511
+ this.pattern = pattern;
15512
+ this.mark = mark;
15513
+ this.negative = negative;
15514
+ define2(this, "body", body);
15515
+ define2(this, "ignoreCase", ignoreCase);
15516
+ define2(this, "regexPrefix", prefix);
15517
+ }
15518
+ get regex() {
15519
+ const key2 = UNDERSCORE + MODE_IGNORE;
15520
+ if (this[key2]) {
15521
+ return this[key2];
15736
15522
  }
15523
+ return this._make(MODE_IGNORE, key2);
15524
+ }
15525
+ get checkRegex() {
15526
+ const key2 = UNDERSCORE + MODE_CHECK_IGNORE;
15527
+ if (this[key2]) {
15528
+ return this[key2];
15529
+ }
15530
+ return this._make(MODE_CHECK_IGNORE, key2);
15531
+ }
15532
+ _make(mode, key2) {
15533
+ const str = this.regexPrefix.replace(REGEX_REPLACE_TRAILING_WILDCARD, TRAILING_WILD_CARD_REPLACERS[mode]);
15534
+ const regex = this.ignoreCase ? new RegExp(str, "i") : new RegExp(str);
15535
+ return define2(this, key2, regex);
15737
15536
  }
15738
- this.#modelInfos = infos;
15739
- this.#maxMessages = opts.maxMessages ?? 1000;
15740
- this.#maxCost = opts.maxCost ?? 100;
15741
15537
  }
15742
- #calculageUsage(usage, providerMetadata, modelInfo) {
15743
- const providerMetadataKey = Object.keys(providerMetadata ?? {})[0];
15744
- const metadata = providerMetadata?.[providerMetadataKey] ?? {};
15745
- switch (providerMetadataKey) {
15746
- case "openrouter":
15747
- return {
15748
- input: usage.inputTokens ?? 0,
15749
- output: usage.outputTokens ?? 0,
15750
- cachedRead: usage.cachedInputTokens ?? 0,
15751
- cost: metadata.usage?.cost ?? 0
15752
- };
15753
- case "anthropic": {
15754
- const cachedRead = usage.cachedInputTokens ?? 0;
15755
- const cacheWrite = metadata?.promptCacheMissTokens ?? 0;
15756
- const input = usage.inputTokens ?? 0;
15757
- const output = usage.outputTokens ?? 0;
15758
- return {
15759
- input: input + cacheWrite + cachedRead,
15760
- output,
15761
- cachedRead,
15762
- cost: (input * modelInfo.inputPrice + output * modelInfo.outputPrice + cacheWrite * modelInfo.cacheWritesPrice + cachedRead * modelInfo.cacheReadsPrice) / 1e6
15763
- };
15538
+ var createRule = ({
15539
+ pattern,
15540
+ mark
15541
+ }, ignoreCase) => {
15542
+ let negative = false;
15543
+ let body = pattern;
15544
+ if (body.indexOf("!") === 0) {
15545
+ negative = true;
15546
+ body = body.substr(1);
15547
+ }
15548
+ body = body.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, "!").replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, "#");
15549
+ const regexPrefix = makeRegexPrefix(body);
15550
+ return new IgnoreRule(pattern, mark, body, ignoreCase, negative, regexPrefix);
15551
+ };
15552
+
15553
+ class RuleManager {
15554
+ constructor(ignoreCase) {
15555
+ this._ignoreCase = ignoreCase;
15556
+ this._rules = [];
15557
+ }
15558
+ _add(pattern) {
15559
+ if (pattern && pattern[KEY_IGNORE]) {
15560
+ this._rules = this._rules.concat(pattern._rules._rules);
15561
+ this._added = true;
15562
+ return;
15764
15563
  }
15765
- case "deepseek": {
15766
- const cachedRead = usage.cachedInputTokens ?? 0;
15767
- const cacheWrite = metadata.promptCacheMissTokens ?? 0;
15768
- const input = usage.inputTokens ?? 0;
15769
- const output = usage.outputTokens ?? 0;
15770
- return {
15771
- input,
15772
- output,
15773
- cachedRead,
15774
- cost: (output * modelInfo.outputPrice + cacheWrite * modelInfo.inputPrice + cachedRead * modelInfo.cacheReadsPrice) / 1e6
15564
+ if (isString(pattern)) {
15565
+ pattern = {
15566
+ pattern
15775
15567
  };
15776
15568
  }
15777
- default: {
15778
- const cachedRead = usage.cachedInputTokens ?? 0;
15779
- const input = usage.inputTokens ?? 0;
15780
- const output = usage.outputTokens ?? 0;
15781
- return {
15782
- input,
15783
- output,
15784
- cachedRead,
15785
- cost: (input * modelInfo.inputPrice + output * modelInfo.outputPrice) / 1e6
15786
- };
15569
+ if (checkPattern(pattern.pattern)) {
15570
+ const rule = createRule(pattern, this._ignoreCase);
15571
+ this._added = true;
15572
+ this._rules.push(rule);
15787
15573
  }
15788
15574
  }
15789
- }
15790
- addUsage(llm, resp, options = {}) {
15791
- const modelInfo = options.modelInfo ?? this.#modelInfos[`${llm.provider.split(".")[0]}:${llm.modelId.replace(/[\.-]/g, "")}`] ?? {
15792
- inputPrice: 0,
15793
- outputPrice: 0,
15794
- cacheWritesPrice: 0,
15795
- cacheReadsPrice: 0
15796
- };
15797
- const usage = "totalUsage" in resp ? resp.totalUsage : resp.usage;
15798
- const result = this.#calculageUsage(usage, resp.providerMetadata, modelInfo);
15799
- this.#totals.input += result.input;
15800
- this.#totals.output += result.output;
15801
- this.#totals.cachedRead += result.cachedRead;
15802
- this.#totals.cost += result.cost;
15803
- this.#calls++;
15804
- }
15805
- setUsage(newUsage) {
15806
- if (newUsage.input != null)
15807
- this.#totals.input = newUsage.input;
15808
- if (newUsage.output != null)
15809
- this.#totals.output = newUsage.output;
15810
- if (newUsage.cachedRead != null)
15811
- this.#totals.cachedRead = newUsage.cachedRead;
15812
- if (newUsage.cost != null)
15813
- this.#totals.cost = newUsage.cost;
15814
- if (newUsage.calls != null)
15815
- this.#calls = newUsage.calls;
15816
- }
15817
- incrementMessageCount(n = 1) {
15818
- this.#calls += n;
15819
- }
15820
- isLimitExceeded() {
15821
- const messageCount = this.#maxMessages !== undefined && this.#calls >= this.#maxMessages;
15822
- const cost = this.#maxCost !== undefined && this.#totals.cost >= this.#maxCost;
15823
- return {
15824
- messageCount,
15825
- maxMessages: this.#maxMessages,
15826
- cost,
15827
- maxCost: this.#maxCost,
15828
- result: messageCount || cost
15829
- };
15830
- }
15831
- checkLimit() {
15832
- const result = this.isLimitExceeded();
15833
- if (result.result) {
15834
- throw new Error(`Usage limit exceeded. Message count: ${result.messageCount}/${result.maxMessages}, cost: ${result.cost}/${result.maxCost}`);
15575
+ add(pattern) {
15576
+ this._added = false;
15577
+ makeArray(isString(pattern) ? splitPattern(pattern) : pattern).forEach(this._add, this);
15578
+ return this._added;
15579
+ }
15580
+ test(path, checkUnignored, mode) {
15581
+ let ignored = false;
15582
+ let unignored = false;
15583
+ let matchedRule;
15584
+ this._rules.forEach((rule) => {
15585
+ const { negative } = rule;
15586
+ if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
15587
+ return;
15588
+ }
15589
+ const matched = rule[mode].test(path);
15590
+ if (!matched) {
15591
+ return;
15592
+ }
15593
+ ignored = !negative;
15594
+ unignored = negative;
15595
+ matchedRule = negative ? UNDEFINED : rule;
15596
+ });
15597
+ const ret = {
15598
+ ignored,
15599
+ unignored
15600
+ };
15601
+ if (matchedRule) {
15602
+ ret.rule = matchedRule;
15603
+ }
15604
+ return ret;
15835
15605
  }
15836
15606
  }
15837
- get usage() {
15838
- return { ...this.#totals, messageCount: this.#calls };
15839
- }
15840
- printUsage() {
15841
- const u = this.usage;
15842
- console.log(`Usage - messages: ${u.messageCount}, input: ${u.input}, cached: ${u.cachedRead}, ` + `output: ${u.output}, cost: $${u.cost.toFixed(4)}`);
15607
+ var throwError = (message, Ctor) => {
15608
+ throw new Ctor(message);
15609
+ };
15610
+ var checkPath = (path, originalPath, doThrow) => {
15611
+ if (!isString(path)) {
15612
+ return doThrow(`path must be a string, but got \`${originalPath}\``, TypeError);
15613
+ }
15614
+ if (!path) {
15615
+ return doThrow(`path must not be empty`, TypeError);
15616
+ }
15617
+ if (checkPath.isNotRelative(path)) {
15618
+ const r = "`path.relative()`d";
15619
+ return doThrow(`path should be a ${r} string, but got "${originalPath}"`, RangeError);
15620
+ }
15621
+ return true;
15622
+ };
15623
+ var isNotRelative = (path) => REGEX_TEST_INVALID_PATH.test(path);
15624
+ checkPath.isNotRelative = isNotRelative;
15625
+ checkPath.convert = (p) => p;
15626
+
15627
+ class Ignore {
15628
+ constructor({
15629
+ ignorecase = true,
15630
+ ignoreCase = ignorecase,
15631
+ allowRelativePaths = false
15632
+ } = {}) {
15633
+ define2(this, KEY_IGNORE, true);
15634
+ this._rules = new RuleManager(ignoreCase);
15635
+ this._strictPathCheck = !allowRelativePaths;
15636
+ this._initCache();
15637
+ }
15638
+ _initCache() {
15639
+ this._ignoreCache = Object.create(null);
15640
+ this._testCache = Object.create(null);
15641
+ }
15642
+ add(pattern) {
15643
+ if (this._rules.add(pattern)) {
15644
+ this._initCache();
15645
+ }
15646
+ return this;
15647
+ }
15648
+ addPattern(pattern) {
15649
+ return this.add(pattern);
15650
+ }
15651
+ _test(originalPath, cache, checkUnignored, slices) {
15652
+ const path = originalPath && checkPath.convert(originalPath);
15653
+ checkPath(path, originalPath, this._strictPathCheck ? throwError : RETURN_FALSE);
15654
+ return this._t(path, cache, checkUnignored, slices);
15655
+ }
15656
+ checkIgnore(path) {
15657
+ if (!REGEX_TEST_TRAILING_SLASH.test(path)) {
15658
+ return this.test(path);
15659
+ }
15660
+ const slices = path.split(SLASH).filter(Boolean);
15661
+ slices.pop();
15662
+ if (slices.length) {
15663
+ const parent = this._t(slices.join(SLASH) + SLASH, this._testCache, true, slices);
15664
+ if (parent.ignored) {
15665
+ return parent;
15666
+ }
15667
+ }
15668
+ return this._rules.test(path, false, MODE_CHECK_IGNORE);
15669
+ }
15670
+ _t(path, cache, checkUnignored, slices) {
15671
+ if (path in cache) {
15672
+ return cache[path];
15673
+ }
15674
+ if (!slices) {
15675
+ slices = path.split(SLASH).filter(Boolean);
15676
+ }
15677
+ slices.pop();
15678
+ if (!slices.length) {
15679
+ return cache[path] = this._rules.test(path, checkUnignored, MODE_IGNORE);
15680
+ }
15681
+ const parent = this._t(slices.join(SLASH) + SLASH, cache, checkUnignored, slices);
15682
+ return cache[path] = parent.ignored ? parent : this._rules.test(path, checkUnignored, MODE_IGNORE);
15683
+ }
15684
+ ignores(path) {
15685
+ return this._test(path, this._ignoreCache, false).ignored;
15686
+ }
15687
+ createFilter() {
15688
+ return (path) => !this.ignores(path);
15689
+ }
15690
+ filter(paths) {
15691
+ return makeArray(paths).filter(this.createFilter());
15692
+ }
15693
+ test(path) {
15694
+ return this._test(path, this._testCache, true);
15695
+ }
15843
15696
  }
15844
- onFinishHandler(llm) {
15845
- return (evt) => {
15846
- this.addUsage(llm, evt);
15847
- };
15697
+ var factory = (options) => new Ignore(options);
15698
+ var isPathValid = (path) => checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
15699
+ var setupWindows = () => {
15700
+ const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
15701
+ checkPath.convert = makePosix;
15702
+ const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
15703
+ checkPath.isNotRelative = (path) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
15704
+ };
15705
+ if (typeof process !== "undefined" && process.platform === "win32") {
15706
+ setupWindows();
15848
15707
  }
15849
- }
15708
+ module.exports = factory;
15709
+ factory.default = factory;
15710
+ module.exports.isPathValid = isPathValid;
15711
+ define2(module.exports, Symbol.for("setupWindows"), setupWindows);
15712
+ });
15713
+
15714
+ // src/config.ts
15715
+ import { existsSync, readFileSync } from "node:fs";
15716
+ import { homedir } from "node:os";
15717
+ import { join } from "node:path";
15718
+
15850
15719
  // ../core/src/tools/allTools.ts
15851
15720
  var exports_allTools = {};
15852
15721
  __export(exports_allTools, {
@@ -27050,7 +26919,7 @@ var handler2 = async (provider, args) => {
27050
26919
  message: `<user_message>${moreMessage}</user_message>`
27051
26920
  };
27052
26921
  };
27053
- var isAvailable2 = (provider) => {
26922
+ var isAvailable2 = (_provider) => {
27054
26923
  return true;
27055
26924
  };
27056
26925
  var attemptCompletion_default = {
@@ -27277,8 +27146,73 @@ var fetchUrl_default = {
27277
27146
  handler: handler5,
27278
27147
  isAvailable: isAvailable5
27279
27148
  };
27280
- // ../core/src/tools/listFiles.ts
27149
+ // ../core/src/tools/handOver.ts
27281
27150
  var toolInfo6 = {
27151
+ name: "hand_over",
27152
+ description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
27153
+ parameters: exports_external.object({
27154
+ agentName: exports_external.string().describe("The name of the agent to hand over the task to").meta({ usageValue: "Name of the target agent" }),
27155
+ task: exports_external.string().describe("The task to be completed by the target agent").meta({ usageValue: "Task description" }),
27156
+ context: exports_external.string().describe("The context information for the task").meta({ usageValue: "Context information" }),
27157
+ files: exports_external.preprocess((val) => {
27158
+ if (!val)
27159
+ return [];
27160
+ const values = Array.isArray(val) ? val : [val];
27161
+ return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
27162
+ }, exports_external.array(exports_external.string())).optional().describe("The files relevant to the task. Comma separated paths").meta({ usageValue: "Relevant files" })
27163
+ }),
27164
+ examples: [
27165
+ {
27166
+ description: "Hand over a coding task to the coder agent",
27167
+ parameters: [
27168
+ {
27169
+ name: "agentName",
27170
+ value: "coder"
27171
+ },
27172
+ {
27173
+ name: "task",
27174
+ value: "Implement the login feature"
27175
+ },
27176
+ {
27177
+ name: "context",
27178
+ value: "We need a secure login system with email and password"
27179
+ },
27180
+ {
27181
+ name: "files",
27182
+ value: "src/auth/login.ts,src/auth/types.ts"
27183
+ }
27184
+ ]
27185
+ }
27186
+ ],
27187
+ permissionLevel: 0 /* None */
27188
+ };
27189
+ var handler6 = async (_provider, args) => {
27190
+ const parsed = toolInfo6.parameters.safeParse(args);
27191
+ if (!parsed.success) {
27192
+ return {
27193
+ type: "Invalid" /* Invalid */,
27194
+ message: `Invalid arguments for hand_over: ${parsed.error.message}`
27195
+ };
27196
+ }
27197
+ const { agentName, task, context, files } = parsed.data;
27198
+ return {
27199
+ type: "HandOver" /* HandOver */,
27200
+ agentName,
27201
+ task,
27202
+ context,
27203
+ files: files ?? []
27204
+ };
27205
+ };
27206
+ var isAvailable6 = (_provider) => {
27207
+ return true;
27208
+ };
27209
+ var handOver_default = {
27210
+ ...toolInfo6,
27211
+ handler: handler6,
27212
+ isAvailable: isAvailable6
27213
+ };
27214
+ // ../core/src/tools/listFiles.ts
27215
+ var toolInfo7 = {
27282
27216
  name: "list_files",
27283
27217
  description: "Request to list files and directories within the specified directory. If recursive is true, it will list all files and directories recursively. If recursive is false or not provided, it will only list the top-level contents. Do not use this tool to confirm the existence of files you may have created, as the user will let you know if the files were created successfully or not.",
27284
27218
  parameters: exports_external.object({
@@ -27312,14 +27246,14 @@ var toolInfo6 = {
27312
27246
  ],
27313
27247
  permissionLevel: 1 /* Read */
27314
27248
  };
27315
- var handler6 = async (provider, args) => {
27249
+ var handler7 = async (provider, args) => {
27316
27250
  if (!provider.listFiles) {
27317
27251
  return {
27318
27252
  type: "Error" /* Error */,
27319
27253
  message: "Not possible to list files. Abort."
27320
27254
  };
27321
27255
  }
27322
- const { path, maxCount, recursive } = toolInfo6.parameters.parse(args);
27256
+ const { path, maxCount, recursive } = toolInfo7.parameters.parse(args);
27323
27257
  const [files, limitReached] = await provider.listFiles(path, recursive, maxCount);
27324
27258
  return {
27325
27259
  type: "Reply" /* Reply */,
@@ -27331,16 +27265,16 @@ ${files.join(`
27331
27265
  <list_files_truncated>${limitReached}</list_files_truncated>`
27332
27266
  };
27333
27267
  };
27334
- var isAvailable6 = (provider) => {
27268
+ var isAvailable7 = (provider) => {
27335
27269
  return !!provider.listFiles;
27336
27270
  };
27337
27271
  var listFiles_default = {
27338
- ...toolInfo6,
27339
- handler: handler6,
27340
- isAvailable: isAvailable6
27272
+ ...toolInfo7,
27273
+ handler: handler7,
27274
+ isAvailable: isAvailable7
27341
27275
  };
27342
27276
  // ../core/src/tools/readFile.ts
27343
- var toolInfo7 = {
27277
+ var toolInfo8 = {
27344
27278
  name: "read_file",
27345
27279
  description: "Request to read the contents of one or multiple files at the specified paths. Use comma separated paths to read multiple files. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. May not be suitable for other types of binary files, as it returns the raw content as a string. Try to list all the potential files are relevent to the task, and then use this tool to read all the relevant files.",
27346
27280
  parameters: exports_external.object({
@@ -27373,14 +27307,14 @@ var toolInfo7 = {
27373
27307
  ],
27374
27308
  permissionLevel: 1 /* Read */
27375
27309
  };
27376
- var handler7 = async (provider, args) => {
27310
+ var handler8 = async (provider, args) => {
27377
27311
  if (!provider.readFile) {
27378
27312
  return {
27379
27313
  type: "Error" /* Error */,
27380
27314
  message: "Not possible to read file. Abort."
27381
27315
  };
27382
27316
  }
27383
- const { path: paths } = toolInfo7.parameters.parse(args);
27317
+ const { path: paths } = toolInfo8.parameters.parse(args);
27384
27318
  const resp = [];
27385
27319
  for (const path of paths) {
27386
27320
  const fileContent = await provider.readFile(path);
@@ -27401,13 +27335,109 @@ var handler7 = async (provider, args) => {
27401
27335
  `)
27402
27336
  };
27403
27337
  };
27404
- var isAvailable7 = (provider) => {
27338
+ var isAvailable8 = (provider) => {
27405
27339
  return !!provider.readFile;
27406
27340
  };
27407
27341
  var readFile_default = {
27408
- ...toolInfo7,
27409
- handler: handler7,
27410
- isAvailable: isAvailable7
27342
+ ...toolInfo8,
27343
+ handler: handler8,
27344
+ isAvailable: isAvailable8
27345
+ };
27346
+ // ../core/src/tools/removeFile.ts
27347
+ var toolInfo9 = {
27348
+ name: "remove_file",
27349
+ description: "Request to remove a file at the specified path.",
27350
+ parameters: exports_external.object({
27351
+ path: exports_external.string().describe("The path of the file to remove").meta({ usageValue: "File path here" })
27352
+ }),
27353
+ examples: [
27354
+ {
27355
+ description: "Request to remove a file",
27356
+ parameters: [
27357
+ {
27358
+ name: "path",
27359
+ value: "src/main.js"
27360
+ }
27361
+ ]
27362
+ }
27363
+ ],
27364
+ permissionLevel: 2 /* Write */
27365
+ };
27366
+ var handler9 = async (provider, args) => {
27367
+ if (!provider.removeFile) {
27368
+ return {
27369
+ type: "Error" /* Error */,
27370
+ message: "Not possible to remove file. Abort."
27371
+ };
27372
+ }
27373
+ const parsed = toolInfo9.parameters.safeParse(args);
27374
+ if (!parsed.success) {
27375
+ return {
27376
+ type: "Invalid" /* Invalid */,
27377
+ message: `Invalid arguments for remove_file: ${parsed.error.message}`
27378
+ };
27379
+ }
27380
+ const { path } = parsed.data;
27381
+ await provider.removeFile(path);
27382
+ return {
27383
+ type: "Reply" /* Reply */,
27384
+ message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
27385
+ };
27386
+ };
27387
+ var isAvailable9 = (provider) => {
27388
+ return !!provider.removeFile;
27389
+ };
27390
+ var removeFile_default = {
27391
+ ...toolInfo9,
27392
+ handler: handler9,
27393
+ isAvailable: isAvailable9
27394
+ };
27395
+ // ../core/src/tools/renameFile.ts
27396
+ var toolInfo10 = {
27397
+ name: "rename_file",
27398
+ description: "Request to rename a file from source path to target path.",
27399
+ parameters: exports_external.object({
27400
+ source_path: exports_external.string().describe("The current path of the file").meta({ usageValue: "Source file path here" }),
27401
+ target_path: exports_external.string().describe("The new path for the file").meta({ usageValue: "Target file path here" })
27402
+ }),
27403
+ examples: [
27404
+ {
27405
+ description: "Request to rename a file",
27406
+ parameters: [
27407
+ {
27408
+ name: "source_path",
27409
+ value: "src/old-name.js"
27410
+ },
27411
+ {
27412
+ name: "target_path",
27413
+ value: "src/new-name.js"
27414
+ }
27415
+ ]
27416
+ }
27417
+ ],
27418
+ permissionLevel: 2 /* Write */
27419
+ };
27420
+ var handler10 = async (provider, args) => {
27421
+ if (!provider.renameFile) {
27422
+ return {
27423
+ type: "Error" /* Error */,
27424
+ message: "Not possible to rename file. Abort."
27425
+ };
27426
+ }
27427
+ const { source_path, target_path } = toolInfo10.parameters.parse(args);
27428
+ await provider.renameFile(source_path, target_path);
27429
+ return {
27430
+ type: "Reply" /* Reply */,
27431
+ message: `<rename_file_path>${target_path}</rename_file_path><status>Success</status>`
27432
+ };
27433
+ };
27434
+ var isAvailable10 = (provider) => {
27435
+ return !!provider.renameFile;
27436
+ };
27437
+ var renameFile_default = {
27438
+ ...toolInfo10,
27439
+ handler: handler10,
27440
+ isAvailable: isAvailable10
27411
27441
  };
27412
27442
  // ../core/src/tools/utils/replaceInFile.ts
27413
27443
  var replaceInFile = (fileContent, diff) => {
@@ -27484,7 +27514,7 @@ var replaceInFile = (fileContent, diff) => {
27484
27514
  };
27485
27515
 
27486
27516
  // ../core/src/tools/replaceInFile.ts
27487
- var toolInfo8 = {
27517
+ var toolInfo11 = {
27488
27518
  name: "replace_in_file",
27489
27519
  description: "Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file.",
27490
27520
  parameters: exports_external.object({
@@ -27618,7 +27648,7 @@ function oldFeature() {
27618
27648
  ],
27619
27649
  permissionLevel: 2 /* Write */
27620
27650
  };
27621
- var handler8 = async (provider, args) => {
27651
+ var handler11 = async (provider, args) => {
27622
27652
  if (!provider.readFile || !provider.writeFile) {
27623
27653
  return {
27624
27654
  type: "Error" /* Error */,
@@ -27626,7 +27656,7 @@ var handler8 = async (provider, args) => {
27626
27656
  };
27627
27657
  }
27628
27658
  try {
27629
- const { path, diff } = toolInfo8.parameters.parse(args);
27659
+ const { path, diff } = toolInfo11.parameters.parse(args);
27630
27660
  const fileContent = await provider.readFile(path);
27631
27661
  if (fileContent == null) {
27632
27662
  return {
@@ -27663,16 +27693,16 @@ var handler8 = async (provider, args) => {
27663
27693
  };
27664
27694
  }
27665
27695
  };
27666
- var isAvailable8 = (provider) => {
27696
+ var isAvailable11 = (provider) => {
27667
27697
  return !!provider.readFile && !!provider.writeFile;
27668
27698
  };
27669
27699
  var replaceInFile_default = {
27670
- ...toolInfo8,
27671
- handler: handler8,
27672
- isAvailable: isAvailable8
27700
+ ...toolInfo11,
27701
+ handler: handler11,
27702
+ isAvailable: isAvailable11
27673
27703
  };
27674
27704
  // ../core/src/tools/searchFiles.ts
27675
- var toolInfo9 = {
27705
+ var toolInfo12 = {
27676
27706
  name: "search_files",
27677
27707
  description: "Request to perform a regex search across files in a specified directory, outputting context-rich results that include surrounding lines. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.",
27678
27708
  parameters: exports_external.object({
@@ -27705,7 +27735,7 @@ var toolInfo9 = {
27705
27735
  ],
27706
27736
  permissionLevel: 1 /* Read */
27707
27737
  };
27708
- var handler9 = async (provider, args) => {
27738
+ var handler12 = async (provider, args) => {
27709
27739
  if (!provider.searchFiles) {
27710
27740
  return {
27711
27741
  type: "Error" /* Error */,
@@ -27713,7 +27743,7 @@ var handler9 = async (provider, args) => {
27713
27743
  };
27714
27744
  }
27715
27745
  try {
27716
- const { path, regex, filePattern } = toolInfo9.parameters.parse(args);
27746
+ const { path, regex, filePattern } = toolInfo12.parameters.parse(args);
27717
27747
  const files = await provider.searchFiles(path, regex, filePattern ?? "*");
27718
27748
  return {
27719
27749
  type: "Reply" /* Reply */,
@@ -27733,16 +27763,16 @@ ${files.join(`
27733
27763
  };
27734
27764
  }
27735
27765
  };
27736
- var isAvailable9 = (provider) => {
27766
+ var isAvailable12 = (provider) => {
27737
27767
  return !!provider.searchFiles;
27738
27768
  };
27739
27769
  var searchFiles_default = {
27740
- ...toolInfo9,
27741
- handler: handler9,
27742
- isAvailable: isAvailable9
27770
+ ...toolInfo12,
27771
+ handler: handler12,
27772
+ isAvailable: isAvailable12
27743
27773
  };
27744
27774
  // ../core/src/tools/writeToFile.ts
27745
- var toolInfo10 = {
27775
+ var toolInfo13 = {
27746
27776
  name: "write_to_file",
27747
27777
  description: "Request to write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file. Ensure that the output content does not include incorrect escaped character patterns such as `&lt;`, `&gt;`, or `&amp;`. Also ensure there is no unwanted CDATA tags in the content.",
27748
27778
  parameters: exports_external.object({
@@ -27777,14 +27807,14 @@ export default App;
27777
27807
  ],
27778
27808
  permissionLevel: 2 /* Write */
27779
27809
  };
27780
- var handler10 = async (provider, args) => {
27810
+ var handler13 = async (provider, args) => {
27781
27811
  if (!provider.writeFile) {
27782
27812
  return {
27783
27813
  type: "Error" /* Error */,
27784
27814
  message: "Not possible to write file. Abort."
27785
27815
  };
27786
27816
  }
27787
- const parsed = toolInfo10.parameters.safeParse(args);
27817
+ const parsed = toolInfo13.parameters.safeParse(args);
27788
27818
  if (!parsed.success) {
27789
27819
  return {
27790
27820
  type: "Invalid" /* Invalid */,
@@ -27801,171 +27831,10 @@ var handler10 = async (provider, args) => {
27801
27831
  message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
27802
27832
  };
27803
27833
  };
27804
- var isAvailable10 = (provider) => {
27834
+ var isAvailable13 = (provider) => {
27805
27835
  return !!provider.writeFile;
27806
27836
  };
27807
27837
  var writeToFile_default = {
27808
- ...toolInfo10,
27809
- handler: handler10,
27810
- isAvailable: isAvailable10
27811
- };
27812
- // ../core/src/tools/handOver.ts
27813
- var toolInfo11 = {
27814
- name: "hand_over",
27815
- description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
27816
- parameters: exports_external.object({
27817
- agentName: exports_external.string().describe("The name of the agent to hand over the task to").meta({ usageValue: "Name of the target agent" }),
27818
- task: exports_external.string().describe("The task to be completed by the target agent").meta({ usageValue: "Task description" }),
27819
- context: exports_external.string().describe("The context information for the task").meta({ usageValue: "Context information" }),
27820
- files: exports_external.preprocess((val) => {
27821
- if (!val)
27822
- return [];
27823
- const values = Array.isArray(val) ? val : [val];
27824
- return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
27825
- }, exports_external.array(exports_external.string())).optional().describe("The files relevant to the task. Comma separated paths").meta({ usageValue: "Relevant files" })
27826
- }),
27827
- examples: [
27828
- {
27829
- description: "Hand over a coding task to the coder agent",
27830
- parameters: [
27831
- {
27832
- name: "agentName",
27833
- value: "coder"
27834
- },
27835
- {
27836
- name: "task",
27837
- value: "Implement the login feature"
27838
- },
27839
- {
27840
- name: "context",
27841
- value: "We need a secure login system with email and password"
27842
- },
27843
- {
27844
- name: "files",
27845
- value: "src/auth/login.ts,src/auth/types.ts"
27846
- }
27847
- ]
27848
- }
27849
- ],
27850
- permissionLevel: 0 /* None */
27851
- };
27852
- var handler11 = async (_provider, args) => {
27853
- const parsed = toolInfo11.parameters.safeParse(args);
27854
- if (!parsed.success) {
27855
- return {
27856
- type: "Invalid" /* Invalid */,
27857
- message: `Invalid arguments for hand_over: ${parsed.error.message}`
27858
- };
27859
- }
27860
- const { agentName, task, context, files } = parsed.data;
27861
- return {
27862
- type: "HandOver" /* HandOver */,
27863
- agentName,
27864
- task,
27865
- context,
27866
- files: files ?? []
27867
- };
27868
- };
27869
- var isAvailable11 = (_provider) => {
27870
- return true;
27871
- };
27872
- var handOver_default = {
27873
- ...toolInfo11,
27874
- handler: handler11,
27875
- isAvailable: isAvailable11
27876
- };
27877
- // ../core/src/tools/removeFile.ts
27878
- var toolInfo12 = {
27879
- name: "remove_file",
27880
- description: "Request to remove a file at the specified path.",
27881
- parameters: exports_external.object({
27882
- path: exports_external.string().describe("The path of the file to remove").meta({ usageValue: "File path here" })
27883
- }),
27884
- examples: [
27885
- {
27886
- description: "Request to remove a file",
27887
- parameters: [
27888
- {
27889
- name: "path",
27890
- value: "src/main.js"
27891
- }
27892
- ]
27893
- }
27894
- ],
27895
- permissionLevel: 2 /* Write */
27896
- };
27897
- var handler12 = async (provider, args) => {
27898
- if (!provider.removeFile) {
27899
- return {
27900
- type: "Error" /* Error */,
27901
- message: "Not possible to remove file. Abort."
27902
- };
27903
- }
27904
- const parsed = toolInfo12.parameters.safeParse(args);
27905
- if (!parsed.success) {
27906
- return {
27907
- type: "Invalid" /* Invalid */,
27908
- message: `Invalid arguments for remove_file: ${parsed.error.message}`
27909
- };
27910
- }
27911
- const { path } = parsed.data;
27912
- await provider.removeFile(path);
27913
- return {
27914
- type: "Reply" /* Reply */,
27915
- message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
27916
- };
27917
- };
27918
- var isAvailable12 = (provider) => {
27919
- return !!provider.removeFile;
27920
- };
27921
- var removeFile_default = {
27922
- ...toolInfo12,
27923
- handler: handler12,
27924
- isAvailable: isAvailable12
27925
- };
27926
- // ../core/src/tools/renameFile.ts
27927
- var toolInfo13 = {
27928
- name: "rename_file",
27929
- description: "Request to rename a file from source path to target path.",
27930
- parameters: exports_external.object({
27931
- source_path: exports_external.string().describe("The current path of the file").meta({ usageValue: "Source file path here" }),
27932
- target_path: exports_external.string().describe("The new path for the file").meta({ usageValue: "Target file path here" })
27933
- }),
27934
- examples: [
27935
- {
27936
- description: "Request to rename a file",
27937
- parameters: [
27938
- {
27939
- name: "source_path",
27940
- value: "src/old-name.js"
27941
- },
27942
- {
27943
- name: "target_path",
27944
- value: "src/new-name.js"
27945
- }
27946
- ]
27947
- }
27948
- ],
27949
- permissionLevel: 2 /* Write */
27950
- };
27951
- var handler13 = async (provider, args) => {
27952
- if (!provider.renameFile) {
27953
- return {
27954
- type: "Error" /* Error */,
27955
- message: "Not possible to rename file. Abort."
27956
- };
27957
- }
27958
- const { source_path, target_path } = toolInfo13.parameters.parse(args);
27959
- await provider.renameFile(source_path, target_path);
27960
- return {
27961
- type: "Reply" /* Reply */,
27962
- message: `<rename_file_path>${target_path}</rename_file_path><status>Success</status>`
27963
- };
27964
- };
27965
- var isAvailable13 = (provider) => {
27966
- return !!provider.renameFile;
27967
- };
27968
- var renameFile_default = {
27969
27838
  ...toolInfo13,
27970
27839
  handler: handler13,
27971
27840
  isAvailable: isAvailable13
@@ -28034,6 +27903,142 @@ function toToolInfoV1(tool) {
28034
27903
  };
28035
27904
  }
28036
27905
 
27906
+ // ../core/src/UsageMeter.ts
27907
+ class UsageMeter {
27908
+ #totals = { input: 0, output: 0, cachedRead: 0, cost: 0 };
27909
+ #calls = 0;
27910
+ #modelInfos;
27911
+ #maxMessages;
27912
+ #maxCost;
27913
+ constructor(modelInfos = {}, opts = {}) {
27914
+ const infos = {};
27915
+ for (const [provider2, providerInfo] of Object.entries(modelInfos)) {
27916
+ for (const [model, modelInfo] of Object.entries(providerInfo)) {
27917
+ infos[`${provider2.split("-")[0]}:${model.replace(/[.-]/g, "")}`] = {
27918
+ inputPrice: modelInfo.inputPrice ?? 0,
27919
+ outputPrice: modelInfo.outputPrice ?? 0,
27920
+ cacheWritesPrice: modelInfo.cacheWritesPrice ?? 0,
27921
+ cacheReadsPrice: modelInfo.cacheReadsPrice ?? 0
27922
+ };
27923
+ }
27924
+ }
27925
+ this.#modelInfos = infos;
27926
+ this.#maxMessages = opts.maxMessages ?? 1000;
27927
+ this.#maxCost = opts.maxCost ?? 100;
27928
+ }
27929
+ #calculageUsage(usage, providerMetadata, modelInfo) {
27930
+ const providerMetadataKey = Object.keys(providerMetadata ?? {})[0];
27931
+ const metadata = providerMetadata?.[providerMetadataKey] ?? {};
27932
+ switch (providerMetadataKey) {
27933
+ case "openrouter":
27934
+ return {
27935
+ input: usage.inputTokens ?? 0,
27936
+ output: usage.outputTokens ?? 0,
27937
+ cachedRead: usage.cachedInputTokens ?? 0,
27938
+ cost: metadata.usage?.cost ?? 0
27939
+ };
27940
+ case "anthropic": {
27941
+ const cachedRead = usage.cachedInputTokens ?? 0;
27942
+ const cacheWrite = metadata?.promptCacheMissTokens ?? 0;
27943
+ const input = usage.inputTokens ?? 0;
27944
+ const output = usage.outputTokens ?? 0;
27945
+ return {
27946
+ input: input + cacheWrite + cachedRead,
27947
+ output,
27948
+ cachedRead,
27949
+ cost: (input * modelInfo.inputPrice + output * modelInfo.outputPrice + cacheWrite * modelInfo.cacheWritesPrice + cachedRead * modelInfo.cacheReadsPrice) / 1e6
27950
+ };
27951
+ }
27952
+ case "deepseek": {
27953
+ const cachedRead = usage.cachedInputTokens ?? 0;
27954
+ const cacheWrite = metadata.promptCacheMissTokens ?? 0;
27955
+ const input = usage.inputTokens ?? 0;
27956
+ const output = usage.outputTokens ?? 0;
27957
+ return {
27958
+ input,
27959
+ output,
27960
+ cachedRead,
27961
+ cost: (output * modelInfo.outputPrice + cacheWrite * modelInfo.inputPrice + cachedRead * modelInfo.cacheReadsPrice) / 1e6
27962
+ };
27963
+ }
27964
+ default: {
27965
+ const cachedRead = usage.cachedInputTokens ?? 0;
27966
+ const input = usage.inputTokens ?? 0;
27967
+ const output = usage.outputTokens ?? 0;
27968
+ return {
27969
+ input,
27970
+ output,
27971
+ cachedRead,
27972
+ cost: (input * modelInfo.inputPrice + output * modelInfo.outputPrice) / 1e6
27973
+ };
27974
+ }
27975
+ }
27976
+ }
27977
+ addUsage(llm, resp, options = {}) {
27978
+ const modelInfo = options.modelInfo ?? this.#modelInfos[`${llm.provider.split(".")[0]}:${llm.modelId.replace(/[.-]/g, "")}`] ?? {
27979
+ inputPrice: 0,
27980
+ outputPrice: 0,
27981
+ cacheWritesPrice: 0,
27982
+ cacheReadsPrice: 0
27983
+ };
27984
+ const usage = "totalUsage" in resp ? resp.totalUsage : resp.usage;
27985
+ const result = this.#calculageUsage(usage, resp.providerMetadata, modelInfo);
27986
+ this.#totals.input += result.input;
27987
+ this.#totals.output += result.output;
27988
+ this.#totals.cachedRead += result.cachedRead;
27989
+ this.#totals.cost += result.cost;
27990
+ this.#calls++;
27991
+ }
27992
+ setUsage(newUsage) {
27993
+ if (newUsage.input != null)
27994
+ this.#totals.input = newUsage.input;
27995
+ if (newUsage.output != null)
27996
+ this.#totals.output = newUsage.output;
27997
+ if (newUsage.cachedRead != null)
27998
+ this.#totals.cachedRead = newUsage.cachedRead;
27999
+ if (newUsage.cost != null)
28000
+ this.#totals.cost = newUsage.cost;
28001
+ if (newUsage.calls != null)
28002
+ this.#calls = newUsage.calls;
28003
+ }
28004
+ incrementMessageCount(n = 1) {
28005
+ this.#calls += n;
28006
+ }
28007
+ resetUsage() {
28008
+ this.#totals = { input: 0, output: 0, cachedRead: 0, cost: 0 };
28009
+ this.#calls = 0;
28010
+ }
28011
+ isLimitExceeded() {
28012
+ const messageCount = this.#maxMessages !== undefined && this.#calls >= this.#maxMessages;
28013
+ const cost = this.#maxCost !== undefined && this.#totals.cost >= this.#maxCost;
28014
+ return {
28015
+ messageCount,
28016
+ maxMessages: this.#maxMessages,
28017
+ cost,
28018
+ maxCost: this.#maxCost,
28019
+ result: messageCount || cost
28020
+ };
28021
+ }
28022
+ checkLimit() {
28023
+ const result = this.isLimitExceeded();
28024
+ if (result.result) {
28025
+ throw new Error(`Usage limit exceeded. Message count: ${result.messageCount}/${result.maxMessages}, cost: ${result.cost}/${result.maxCost}`);
28026
+ }
28027
+ }
28028
+ get usage() {
28029
+ return { ...this.#totals, messageCount: this.#calls };
28030
+ }
28031
+ printUsage() {
28032
+ const u = this.usage;
28033
+ console.log(`Usage - messages: ${u.messageCount}, input: ${u.input}, cached: ${u.cachedRead}, ` + `output: ${u.output}, cost: $${u.cost.toFixed(4)}`);
28034
+ }
28035
+ onFinishHandler(llm) {
28036
+ return (evt) => {
28037
+ this.addUsage(llm, evt);
28038
+ };
28039
+ }
28040
+ }
28041
+
28037
28042
  // ../../node_modules/@ai-sdk/provider/dist/index.mjs
28038
28043
  var marker = "vercel.ai.error";
28039
28044
  var symbol2 = Symbol.for(marker);
@@ -50843,7 +50848,7 @@ ${agent.responsibilities.map((resp) => ` - ${resp}`).join(`
50843
50848
  - **Current Agent Role**
50844
50849
  You are currently acting as **${name17}**. If you identify the task is beyond your current scope, use the handover or delegate tool to transition to the other agent. Include sufficient context so the new agent can seamlessly continue the work.
50845
50850
  `;
50846
- var capabilities = (toolNamePrefix) => `
50851
+ var capabilities = (_toolNamePrefix) => `
50847
50852
  ====
50848
50853
 
50849
50854
  CAPABILITIES
@@ -51337,7 +51342,7 @@ RETRY GUIDELINES
51337
51342
  - Explain why the issue remains
51338
51343
  - Suggest manual intervention steps
51339
51344
  - Report any partial improvements`;
51340
- var fullSystemPrompt3 = (info, tools, toolNamePrefix, instructions, scripts, interactive, useNativeTool) => `
51345
+ var fullSystemPrompt3 = (info, tools, toolNamePrefix, instructions, scripts, _interactive, useNativeTool) => `
51341
51346
  ${basePrompt}
51342
51347
  ${useNativeTool ? "" : toolUsePrompt(tools, toolNamePrefix)}
51343
51348
  ${codeFixingStrategies}
@@ -51380,7 +51385,7 @@ class CodeFixerAgent extends AgentBase {
51380
51385
  });
51381
51386
  this.#maxRetries = options.maxRetries ?? 5;
51382
51387
  }
51383
- async onBeforeInvokeTool(name17, args) {
51388
+ async onBeforeInvokeTool(name17, _args) {
51384
51389
  if (name17 === attemptCompletion_default.name) {
51385
51390
  if (this.#retryCount > this.#maxRetries) {
51386
51391
  return;
@@ -51529,7 +51534,10 @@ var configSchema = exports_external.object({
51529
51534
  providers: exports_external.record(exports_external.string(), exports_external.object({
51530
51535
  apiKey: exports_external.string().optional(),
51531
51536
  defaultModel: exports_external.string().optional(),
51532
- defaultParameters: exports_external.record(exports_external.string(), exports_external.any()).optional()
51537
+ defaultParameters: exports_external.record(exports_external.string(), exports_external.any()).optional(),
51538
+ location: exports_external.string().optional(),
51539
+ project: exports_external.string().optional(),
51540
+ keyFile: exports_external.string().optional()
51533
51541
  })).optional(),
51534
51542
  defaultProvider: exports_external.string().optional(),
51535
51543
  defaultModel: exports_external.string().optional(),
@@ -55811,7 +55819,7 @@ function getGlobalConfigPath(home = homedir()) {
55811
55819
  function loadConfigAtPath(path) {
55812
55820
  try {
55813
55821
  return readConfig(path);
55814
- } catch (error81) {
55822
+ } catch (_error) {
55815
55823
  return;
55816
55824
  }
55817
55825
  }
@@ -55895,12 +55903,11 @@ var readConfig = (path) => {
55895
55903
  var readLocalConfig = (path) => {
55896
55904
  try {
55897
55905
  return readConfig(path ?? localConfigFileName);
55898
- } catch (error81) {
55906
+ } catch (_error) {
55899
55907
  return;
55900
55908
  }
55901
55909
  };
55902
55910
  // src/provider.ts
55903
- var import_ignore2 = __toESM(require_ignore(), 1);
55904
55911
  import { spawn as spawn2 } from "node:child_process";
55905
55912
  import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
55906
55913
  import { dirname } from "node:path";
@@ -57178,6 +57185,9 @@ ${theme.style.description(selectedChoice.description)}` : ``;
57178
57185
  return `${[prefix, message, helpTipTop].filter(Boolean).join(" ")}
57179
57186
  ${page}${helpTipBottom}${choiceDescription}${import_ansi_escapes2.default.cursorHide}`;
57180
57187
  });
57188
+ // src/provider.ts
57189
+ var import_ignore2 = __toESM(require_ignore(), 1);
57190
+
57181
57191
  // src/utils/checkRipgrep.ts
57182
57192
  import { spawnSync } from "node:child_process";
57183
57193
  var rgAvailability = {
@@ -57340,7 +57350,7 @@ async function searchFiles(path, regex, filePattern, cwd, excludeFiles) {
57340
57350
  }
57341
57351
 
57342
57352
  // src/provider.ts
57343
- var getProvider = (agentName, config4, options = {}) => {
57353
+ var getProvider = (_agentName, _config, options = {}) => {
57344
57354
  const ig = import_ignore2.default().add(options.excludeFiles ?? []);
57345
57355
  const provider2 = {
57346
57356
  readFile: async (path) => {
@@ -57375,7 +57385,7 @@ var getProvider = (agentName, config4, options = {}) => {
57375
57385
  listFiles: async (path, recursive, maxCount) => {
57376
57386
  return await listFiles(path, recursive, maxCount, process.cwd(), options.excludeFiles);
57377
57387
  },
57378
- executeCommand: (command, needApprove) => {
57388
+ executeCommand: (command, _needApprove) => {
57379
57389
  return new Promise((resolve3, reject) => {
57380
57390
  options.command?.onStarted(command);
57381
57391
  const child = spawn2(command, [], {
@@ -57426,7 +57436,7 @@ var getProvider = (agentName, config4, options = {}) => {
57426
57436
  }
57427
57437
  return answerOptions[0] ?? "<warning>This is non-interactive mode, no answer can be provided.</warning>";
57428
57438
  },
57429
- attemptCompletion: async (result) => {
57439
+ attemptCompletion: async (_result) => {
57430
57440
  return;
57431
57441
  },
57432
57442
  fetchUrl: async (url3) => {