@polka-codes/cli-shared 0.9.62 → 0.9.64

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 +110 -27
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -18794,7 +18794,7 @@ var require_src6 = __commonJS((exports) => {
18794
18794
  var jws = require_jws();
18795
18795
  var path = __require("path");
18796
18796
  var util_1 = __require("util");
18797
- var readFile = fs.readFile ? (0, util_1.promisify)(fs.readFile) : async () => {
18797
+ var readFile2 = fs.readFile ? (0, util_1.promisify)(fs.readFile) : async () => {
18798
18798
  throw new ErrorWithCode("use key rather than keyFile.", "MISSING_CREDENTIALS");
18799
18799
  };
18800
18800
  var GOOGLE_TOKEN_URL = "https://www.googleapis.com/oauth2/v4/token";
@@ -18865,7 +18865,7 @@ var require_src6 = __commonJS((exports) => {
18865
18865
  const ext = path.extname(keyFile);
18866
18866
  switch (ext) {
18867
18867
  case ".json": {
18868
- const key = await readFile(keyFile, "utf8");
18868
+ const key = await readFile2(keyFile, "utf8");
18869
18869
  const body = JSON.parse(key);
18870
18870
  const privateKey = body.private_key;
18871
18871
  const clientEmail = body.client_email;
@@ -18877,7 +18877,7 @@ var require_src6 = __commonJS((exports) => {
18877
18877
  case ".der":
18878
18878
  case ".crt":
18879
18879
  case ".pem": {
18880
- const privateKey = await readFile(keyFile, "utf8");
18880
+ const privateKey = await readFile2(keyFile, "utf8");
18881
18881
  return { privateKey };
18882
18882
  }
18883
18883
  case ".p12":
@@ -20008,7 +20008,7 @@ var require_filesubjecttokensupplier = __commonJS((exports) => {
20008
20008
  exports.FileSubjectTokenSupplier = undefined;
20009
20009
  var util_1 = __require("util");
20010
20010
  var fs = __require("fs");
20011
- var readFile = (0, util_1.promisify)((_a16 = fs.readFile) !== null && _a16 !== undefined ? _a16 : () => {});
20011
+ var readFile2 = (0, util_1.promisify)((_a16 = fs.readFile) !== null && _a16 !== undefined ? _a16 : () => {});
20012
20012
  var realpath = (0, util_1.promisify)((_b8 = fs.realpath) !== null && _b8 !== undefined ? _b8 : () => {});
20013
20013
  var lstat = (0, util_1.promisify)((_c = fs.lstat) !== null && _c !== undefined ? _c : () => {});
20014
20014
 
@@ -20032,7 +20032,7 @@ var require_filesubjecttokensupplier = __commonJS((exports) => {
20032
20032
  throw err;
20033
20033
  }
20034
20034
  let subjectToken;
20035
- const rawText = await readFile(parsedFilePath, { encoding: "utf8" });
20035
+ const rawText = await readFile2(parsedFilePath, { encoding: "utf8" });
20036
20036
  if (this.formatType === "text") {
20037
20037
  subjectToken = rawText;
20038
20038
  } else if (this.formatType === "json" && this.subjectTokenFieldName) {
@@ -33025,6 +33025,7 @@ var require_mimeScore = __commonJS((exports, module) => {
33025
33025
 
33026
33026
  // src/config.ts
33027
33027
  import { existsSync, readFileSync } from "node:fs";
33028
+ import { readFile } from "node:fs/promises";
33028
33029
  import { homedir } from "node:os";
33029
33030
  import { join } from "node:path";
33030
33031
  // ../../node_modules/.bun/zod@4.1.12/node_modules/zod/v4/classic/external.js
@@ -45477,6 +45478,18 @@ var providerModelSchema = exports_external.object({
45477
45478
  parameters: exports_external.record(exports_external.string(), exports_external.any()).optional(),
45478
45479
  budget: exports_external.number().positive().optional()
45479
45480
  });
45481
+ var ruleSchema = exports_external.union([
45482
+ exports_external.string(),
45483
+ exports_external.object({ path: exports_external.string() }).strict(),
45484
+ exports_external.object({ url: exports_external.string() }).strict(),
45485
+ exports_external.object({
45486
+ repo: exports_external.string(),
45487
+ path: exports_external.string(),
45488
+ tag: exports_external.string().optional(),
45489
+ commit: exports_external.string().optional(),
45490
+ branch: exports_external.string().optional()
45491
+ }).strict()
45492
+ ]);
45480
45493
  var configSchema = exports_external.object({
45481
45494
  prices: exports_external.record(exports_external.string(), exports_external.record(exports_external.string(), exports_external.object({
45482
45495
  inputPrice: exports_external.number().optional(),
@@ -45505,7 +45518,10 @@ var configSchema = exports_external.object({
45505
45518
  description: exports_external.string()
45506
45519
  }))).optional(),
45507
45520
  commands: exports_external.record(exports_external.string(), providerModelSchema).optional(),
45508
- rules: exports_external.array(exports_external.string()).optional().or(exports_external.string()).optional(),
45521
+ tools: exports_external.object({
45522
+ search: providerModelSchema.or(exports_external.boolean()).optional()
45523
+ }).optional(),
45524
+ rules: exports_external.array(ruleSchema).optional().or(exports_external.string()).optional(),
45509
45525
  excludeFiles: exports_external.array(exports_external.string()).optional()
45510
45526
  }).strict();
45511
45527
  // ../core/src/tools/askFollowupQuestion.ts
@@ -46485,9 +46501,30 @@ var replaceInFile_default = {
46485
46501
  // ../core/src/tools/search.ts
46486
46502
  var toolInfo14 = {
46487
46503
  name: "search",
46488
- description: "Search the web for information.",
46504
+ description: "Search the web for information using Google Search. Use this tool to find current information, facts, news, documentation, or research that is not available in your training data. Returns comprehensive search results with relevant content extracted from the web.",
46489
46505
  parameters: exports_external.object({
46490
- query: exports_external.string().describe("The query to search for")
46506
+ query: exports_external.string().describe("The query to search for").meta({ usageValue: "Your search query here" })
46507
+ }).meta({
46508
+ examples: [
46509
+ {
46510
+ description: "Search for current events or news",
46511
+ input: {
46512
+ query: "latest developments in AI language models 2024"
46513
+ }
46514
+ },
46515
+ {
46516
+ description: "Look up technical documentation",
46517
+ input: {
46518
+ query: "TypeScript advanced type system features"
46519
+ }
46520
+ },
46521
+ {
46522
+ description: "Research specific information",
46523
+ input: {
46524
+ query: "Node.js performance optimization best practices"
46525
+ }
46526
+ }
46527
+ ]
46491
46528
  })
46492
46529
  };
46493
46530
  var handler14 = async (provider, args) => {
@@ -57631,21 +57668,60 @@ function mergeConfigs(configs) {
57631
57668
  }
57632
57669
  const mergedConfig = configs.reduce((acc, config3) => {
57633
57670
  const merged = merge_default({}, acc, config3);
57634
- let accRules = acc.rules ?? [];
57635
- if (typeof accRules === "string") {
57636
- accRules = [accRules];
57637
- }
57638
- let configRules = config3.rules ?? [];
57639
- if (typeof configRules === "string") {
57640
- configRules = [configRules];
57641
- }
57671
+ const accRules = acc.rules ? Array.isArray(acc.rules) ? acc.rules : [acc.rules] : undefined;
57672
+ const configRules = config3.rules ? Array.isArray(config3.rules) ? config3.rules : [config3.rules] : undefined;
57642
57673
  merged.rules = mergeArray(accRules, configRules);
57643
57674
  merged.excludeFiles = mergeArray(acc.excludeFiles, config3.excludeFiles);
57644
57675
  return merged;
57645
57676
  });
57646
57677
  return mergedConfig;
57647
57678
  }
57648
- function loadConfig(paths, cwd = process.cwd(), home = homedir()) {
57679
+ async function resolveRules(rules) {
57680
+ if (!rules) {
57681
+ return;
57682
+ }
57683
+ if (typeof rules === "string") {
57684
+ return rules;
57685
+ }
57686
+ const resolvedRules = await Promise.all(rules.map(async (rule) => {
57687
+ if (typeof rule === "string") {
57688
+ return rule;
57689
+ }
57690
+ if ("url" in rule) {
57691
+ try {
57692
+ const response = await fetch(rule.url);
57693
+ if (response.ok) {
57694
+ return await response.text();
57695
+ }
57696
+ console.warn(`Failed to fetch rule from ${rule.url}: ${response.statusText}`);
57697
+ } catch (error46) {
57698
+ console.warn(`Error fetching rule from ${rule.url}: ${error46}`);
57699
+ }
57700
+ } else if ("repo" in rule) {
57701
+ const ref = rule.commit ?? rule.tag ?? rule.branch ?? "main";
57702
+ const url2 = `https://raw.githubusercontent.com/${rule.repo}/${ref}/${rule.path}`;
57703
+ try {
57704
+ const response = await fetch(url2);
57705
+ if (response.ok) {
57706
+ return await response.text();
57707
+ }
57708
+ console.warn(`Failed to fetch rule from ${url2}: ${response.statusText}`);
57709
+ } catch (error46) {
57710
+ console.warn(`Error fetching rule from ${url2}: ${error46}`);
57711
+ }
57712
+ } else if ("path" in rule) {
57713
+ if (existsSync(rule.path)) {
57714
+ return await readFile(rule.path, "utf-8");
57715
+ }
57716
+ console.warn(`Rule file not found: ${rule.path}`);
57717
+ }
57718
+ return;
57719
+ }));
57720
+ return resolvedRules.filter((rule) => rule !== undefined).join(`
57721
+
57722
+ `);
57723
+ }
57724
+ async function loadConfig(paths, cwd = process.cwd(), home = homedir()) {
57649
57725
  const configs = [];
57650
57726
  const globalConfigPath = getGlobalConfigPath(home);
57651
57727
  if (existsSync(globalConfigPath)) {
@@ -57682,7 +57758,15 @@ ${error46}`);
57682
57758
  }
57683
57759
  }
57684
57760
  }
57685
- return configs.length > 0 ? mergeConfigs(configs) : undefined;
57761
+ const mergedConfig = configs.length > 0 ? mergeConfigs(configs) : undefined;
57762
+ if (!mergedConfig) {
57763
+ return;
57764
+ }
57765
+ const resolvedRules = await resolveRules(mergedConfig.rules);
57766
+ return {
57767
+ ...mergedConfig,
57768
+ rules: resolvedRules
57769
+ };
57686
57770
  }
57687
57771
  var readConfig = (path) => {
57688
57772
  const file2 = readFileSync(path, "utf8");
@@ -57698,7 +57782,7 @@ var readLocalConfig = (path) => {
57698
57782
  };
57699
57783
  // src/provider.ts
57700
57784
  import { spawn as spawn2 } from "node:child_process";
57701
- import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
57785
+ import { mkdir, readFile as readFile2, rename, unlink, writeFile } from "node:fs/promises";
57702
57786
  import { dirname, normalize, resolve as resolve3 } from "node:path";
57703
57787
 
57704
57788
  // ../../node_modules/.bun/@ai-sdk+google-vertex@3.0.68+5954958163efbb2a/node_modules/@ai-sdk/google-vertex/dist/index.mjs
@@ -60747,6 +60831,7 @@ var getProvider = (options = {}) => {
60747
60831
  const memoryStore = options.memoryStore ?? new InMemoryStore;
60748
60832
  const todoItemStore = options.todoItemStore ?? new InMemoryStore;
60749
60833
  const defaultMemoryTopic = ":default:";
60834
+ const searchModel = options.getModel?.("search");
60750
60835
  const provider2 = {
60751
60836
  listTodoItems: async (id, status) => {
60752
60837
  const todoItems = await todoItemStore.read() ?? [];
@@ -60880,7 +60965,7 @@ ${content}`;
60880
60965
  throw new Error(`Not allow to access file ${path}`);
60881
60966
  }
60882
60967
  try {
60883
- return await readFile(path, "utf8");
60968
+ return await readFile2(path, "utf8");
60884
60969
  } catch (_e) {
60885
60970
  return;
60886
60971
  }
@@ -60914,7 +60999,7 @@ ${content}`;
60914
60999
  if (!resolvedPath.startsWith(process.cwd())) {
60915
61000
  throw new Error(`Access to file path "${filePath}" is restricted.`);
60916
61001
  }
60917
- const data2 = await readFile(resolvedPath);
61002
+ const data2 = await readFile2(resolvedPath);
60918
61003
  const mediaType2 = $lookup(resolvedPath) || "application/octet-stream";
60919
61004
  return {
60920
61005
  base64Data: data2.toString("base64"),
@@ -61011,13 +61096,10 @@ ${content}`;
61011
61096
  throw error46;
61012
61097
  }
61013
61098
  },
61014
- search: options.getModel && (async (query) => {
61015
- const model = options.getModel?.("search");
61016
- if (!model) {
61017
- throw new Error("Unable to get model for search");
61018
- }
61099
+ search: searchModel && (async (query) => {
61019
61100
  const resp = await generateText({
61020
- model,
61101
+ model: searchModel,
61102
+ system: "You are a web search assistant. When searching for information, provide comprehensive and detailed results. Include relevant facts, statistics, dates, and key details from the search results. Synthesize information from multiple sources when available. Structure your response clearly with the most relevant information first. Reference or cite sources when presenting specific claims or data.",
61021
61103
  tools: {
61022
61104
  google_search: vertex.tools.googleSearch({})
61023
61105
  },
@@ -61820,6 +61902,7 @@ function readMultiline(prompt = "Enter text (Ctrl+D to finish):") {
61820
61902
  export {
61821
61903
  simplifyToolParameters,
61822
61904
  searchFiles,
61905
+ resolveRules,
61823
61906
  readMultiline,
61824
61907
  readLocalConfig,
61825
61908
  readConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli-shared",
3
- "version": "0.9.62",
3
+ "version": "0.9.64",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",
@@ -17,12 +17,12 @@
17
17
  "build": "bun build src/index.ts --outdir dist --target node"
18
18
  },
19
19
  "dependencies": {
20
- "@ai-sdk/google-vertex": "^3.0.68",
20
+ "@ai-sdk/google-vertex": "^3.0.71",
21
21
  "@ai-sdk/provider": "^2.0.0",
22
22
  "@ai-sdk/provider-utils": "^3.0.15",
23
- "@inquirer/prompts": "^7.9.0",
24
- "@polka-codes/core": "0.9.61",
25
- "ai": "^5.0.95",
23
+ "@inquirer/prompts": "^7.10.1",
24
+ "@polka-codes/core": "0.9.63",
25
+ "ai": "^5.0.97",
26
26
  "chalk": "^5.6.2",
27
27
  "ignore": "^7.0.5",
28
28
  "lodash-es": "^4.17.21",