@polka-codes/cli 0.2.0 → 0.3.0

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 +381 -4
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -28,6 +28,380 @@ var __export = (target, all) => {
28
28
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
29
29
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
30
30
 
31
+ // ../../node_modules/dotenv/package.json
32
+ var require_package = __commonJS((exports, module) => {
33
+ module.exports = {
34
+ name: "dotenv",
35
+ version: "16.4.7",
36
+ description: "Loads environment variables from .env file",
37
+ main: "lib/main.js",
38
+ types: "lib/main.d.ts",
39
+ exports: {
40
+ ".": {
41
+ types: "./lib/main.d.ts",
42
+ require: "./lib/main.js",
43
+ default: "./lib/main.js"
44
+ },
45
+ "./config": "./config.js",
46
+ "./config.js": "./config.js",
47
+ "./lib/env-options": "./lib/env-options.js",
48
+ "./lib/env-options.js": "./lib/env-options.js",
49
+ "./lib/cli-options": "./lib/cli-options.js",
50
+ "./lib/cli-options.js": "./lib/cli-options.js",
51
+ "./package.json": "./package.json"
52
+ },
53
+ scripts: {
54
+ "dts-check": "tsc --project tests/types/tsconfig.json",
55
+ lint: "standard",
56
+ pretest: "npm run lint && npm run dts-check",
57
+ test: "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
58
+ "test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=lcov",
59
+ prerelease: "npm test",
60
+ release: "standard-version"
61
+ },
62
+ repository: {
63
+ type: "git",
64
+ url: "git://github.com/motdotla/dotenv.git"
65
+ },
66
+ funding: "https://dotenvx.com",
67
+ keywords: [
68
+ "dotenv",
69
+ "env",
70
+ ".env",
71
+ "environment",
72
+ "variables",
73
+ "config",
74
+ "settings"
75
+ ],
76
+ readmeFilename: "README.md",
77
+ license: "BSD-2-Clause",
78
+ devDependencies: {
79
+ "@types/node": "^18.11.3",
80
+ decache: "^4.6.2",
81
+ sinon: "^14.0.1",
82
+ standard: "^17.0.0",
83
+ "standard-version": "^9.5.0",
84
+ tap: "^19.2.0",
85
+ typescript: "^4.8.4"
86
+ },
87
+ engines: {
88
+ node: ">=12"
89
+ },
90
+ browser: {
91
+ fs: false
92
+ }
93
+ };
94
+ });
95
+
96
+ // ../../node_modules/dotenv/lib/main.js
97
+ var require_main = __commonJS((exports, module) => {
98
+ var fs = __require("fs");
99
+ var path = __require("path");
100
+ var os = __require("os");
101
+ var crypto = __require("crypto");
102
+ var packageJson = require_package();
103
+ var version = packageJson.version;
104
+ var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
105
+ function parse(src) {
106
+ const obj = {};
107
+ let lines = src.toString();
108
+ lines = lines.replace(/\r\n?/mg, `
109
+ `);
110
+ let match;
111
+ while ((match = LINE.exec(lines)) != null) {
112
+ const key = match[1];
113
+ let value = match[2] || "";
114
+ value = value.trim();
115
+ const maybeQuote = value[0];
116
+ value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
117
+ if (maybeQuote === '"') {
118
+ value = value.replace(/\\n/g, `
119
+ `);
120
+ value = value.replace(/\\r/g, "\r");
121
+ }
122
+ obj[key] = value;
123
+ }
124
+ return obj;
125
+ }
126
+ function _parseVault(options) {
127
+ const vaultPath = _vaultPath(options);
128
+ const result = DotenvModule.configDotenv({ path: vaultPath });
129
+ if (!result.parsed) {
130
+ const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
131
+ err.code = "MISSING_DATA";
132
+ throw err;
133
+ }
134
+ const keys = _dotenvKey(options).split(",");
135
+ const length = keys.length;
136
+ let decrypted;
137
+ for (let i = 0;i < length; i++) {
138
+ try {
139
+ const key = keys[i].trim();
140
+ const attrs = _instructions(result, key);
141
+ decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
142
+ break;
143
+ } catch (error) {
144
+ if (i + 1 >= length) {
145
+ throw error;
146
+ }
147
+ }
148
+ }
149
+ return DotenvModule.parse(decrypted);
150
+ }
151
+ function _log(message) {
152
+ console.log(`[dotenv@${version}][INFO] ${message}`);
153
+ }
154
+ function _warn(message) {
155
+ console.log(`[dotenv@${version}][WARN] ${message}`);
156
+ }
157
+ function _debug(message) {
158
+ console.log(`[dotenv@${version}][DEBUG] ${message}`);
159
+ }
160
+ function _dotenvKey(options) {
161
+ if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
162
+ return options.DOTENV_KEY;
163
+ }
164
+ if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
165
+ return process.env.DOTENV_KEY;
166
+ }
167
+ return "";
168
+ }
169
+ function _instructions(result, dotenvKey) {
170
+ let uri;
171
+ try {
172
+ uri = new URL(dotenvKey);
173
+ } catch (error) {
174
+ if (error.code === "ERR_INVALID_URL") {
175
+ const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
176
+ err.code = "INVALID_DOTENV_KEY";
177
+ throw err;
178
+ }
179
+ throw error;
180
+ }
181
+ const key = uri.password;
182
+ if (!key) {
183
+ const err = new Error("INVALID_DOTENV_KEY: Missing key part");
184
+ err.code = "INVALID_DOTENV_KEY";
185
+ throw err;
186
+ }
187
+ const environment = uri.searchParams.get("environment");
188
+ if (!environment) {
189
+ const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
190
+ err.code = "INVALID_DOTENV_KEY";
191
+ throw err;
192
+ }
193
+ const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
194
+ const ciphertext = result.parsed[environmentKey];
195
+ if (!ciphertext) {
196
+ const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
197
+ err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
198
+ throw err;
199
+ }
200
+ return { ciphertext, key };
201
+ }
202
+ function _vaultPath(options) {
203
+ let possibleVaultPath = null;
204
+ if (options && options.path && options.path.length > 0) {
205
+ if (Array.isArray(options.path)) {
206
+ for (const filepath of options.path) {
207
+ if (fs.existsSync(filepath)) {
208
+ possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
209
+ }
210
+ }
211
+ } else {
212
+ possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
213
+ }
214
+ } else {
215
+ possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
216
+ }
217
+ if (fs.existsSync(possibleVaultPath)) {
218
+ return possibleVaultPath;
219
+ }
220
+ return null;
221
+ }
222
+ function _resolveHome(envPath) {
223
+ return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
224
+ }
225
+ function _configVault(options) {
226
+ _log("Loading env from encrypted .env.vault");
227
+ const parsed = DotenvModule._parseVault(options);
228
+ let processEnv = process.env;
229
+ if (options && options.processEnv != null) {
230
+ processEnv = options.processEnv;
231
+ }
232
+ DotenvModule.populate(processEnv, parsed, options);
233
+ return { parsed };
234
+ }
235
+ function configDotenv(options) {
236
+ const dotenvPath = path.resolve(process.cwd(), ".env");
237
+ let encoding = "utf8";
238
+ const debug = Boolean(options && options.debug);
239
+ if (options && options.encoding) {
240
+ encoding = options.encoding;
241
+ } else {
242
+ if (debug) {
243
+ _debug("No encoding is specified. UTF-8 is used by default");
244
+ }
245
+ }
246
+ let optionPaths = [dotenvPath];
247
+ if (options && options.path) {
248
+ if (!Array.isArray(options.path)) {
249
+ optionPaths = [_resolveHome(options.path)];
250
+ } else {
251
+ optionPaths = [];
252
+ for (const filepath of options.path) {
253
+ optionPaths.push(_resolveHome(filepath));
254
+ }
255
+ }
256
+ }
257
+ let lastError;
258
+ const parsedAll = {};
259
+ for (const path2 of optionPaths) {
260
+ try {
261
+ const parsed = DotenvModule.parse(fs.readFileSync(path2, { encoding }));
262
+ DotenvModule.populate(parsedAll, parsed, options);
263
+ } catch (e) {
264
+ if (debug) {
265
+ _debug(`Failed to load ${path2} ${e.message}`);
266
+ }
267
+ lastError = e;
268
+ }
269
+ }
270
+ let processEnv = process.env;
271
+ if (options && options.processEnv != null) {
272
+ processEnv = options.processEnv;
273
+ }
274
+ DotenvModule.populate(processEnv, parsedAll, options);
275
+ if (lastError) {
276
+ return { parsed: parsedAll, error: lastError };
277
+ } else {
278
+ return { parsed: parsedAll };
279
+ }
280
+ }
281
+ function config(options) {
282
+ if (_dotenvKey(options).length === 0) {
283
+ return DotenvModule.configDotenv(options);
284
+ }
285
+ const vaultPath = _vaultPath(options);
286
+ if (!vaultPath) {
287
+ _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
288
+ return DotenvModule.configDotenv(options);
289
+ }
290
+ return DotenvModule._configVault(options);
291
+ }
292
+ function decrypt(encrypted, keyStr) {
293
+ const key = Buffer.from(keyStr.slice(-64), "hex");
294
+ let ciphertext = Buffer.from(encrypted, "base64");
295
+ const nonce = ciphertext.subarray(0, 12);
296
+ const authTag = ciphertext.subarray(-16);
297
+ ciphertext = ciphertext.subarray(12, -16);
298
+ try {
299
+ const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
300
+ aesgcm.setAuthTag(authTag);
301
+ return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
302
+ } catch (error) {
303
+ const isRange = error instanceof RangeError;
304
+ const invalidKeyLength = error.message === "Invalid key length";
305
+ const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
306
+ if (isRange || invalidKeyLength) {
307
+ const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
308
+ err.code = "INVALID_DOTENV_KEY";
309
+ throw err;
310
+ } else if (decryptionFailed) {
311
+ const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
312
+ err.code = "DECRYPTION_FAILED";
313
+ throw err;
314
+ } else {
315
+ throw error;
316
+ }
317
+ }
318
+ }
319
+ function populate(processEnv, parsed, options = {}) {
320
+ const debug = Boolean(options && options.debug);
321
+ const override = Boolean(options && options.override);
322
+ if (typeof parsed !== "object") {
323
+ const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
324
+ err.code = "OBJECT_REQUIRED";
325
+ throw err;
326
+ }
327
+ for (const key of Object.keys(parsed)) {
328
+ if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
329
+ if (override === true) {
330
+ processEnv[key] = parsed[key];
331
+ }
332
+ if (debug) {
333
+ if (override === true) {
334
+ _debug(`"${key}" is already defined and WAS overwritten`);
335
+ } else {
336
+ _debug(`"${key}" is already defined and was NOT overwritten`);
337
+ }
338
+ }
339
+ } else {
340
+ processEnv[key] = parsed[key];
341
+ }
342
+ }
343
+ }
344
+ var DotenvModule = {
345
+ configDotenv,
346
+ _configVault,
347
+ _parseVault,
348
+ config,
349
+ decrypt,
350
+ parse,
351
+ populate
352
+ };
353
+ exports.configDotenv = DotenvModule.configDotenv;
354
+ exports._configVault = DotenvModule._configVault;
355
+ exports._parseVault = DotenvModule._parseVault;
356
+ exports.config = DotenvModule.config;
357
+ exports.decrypt = DotenvModule.decrypt;
358
+ exports.parse = DotenvModule.parse;
359
+ exports.populate = DotenvModule.populate;
360
+ module.exports = DotenvModule;
361
+ });
362
+
363
+ // ../../node_modules/dotenv/lib/env-options.js
364
+ var require_env_options = __commonJS((exports, module) => {
365
+ var options = {};
366
+ if (process.env.DOTENV_CONFIG_ENCODING != null) {
367
+ options.encoding = process.env.DOTENV_CONFIG_ENCODING;
368
+ }
369
+ if (process.env.DOTENV_CONFIG_PATH != null) {
370
+ options.path = process.env.DOTENV_CONFIG_PATH;
371
+ }
372
+ if (process.env.DOTENV_CONFIG_DEBUG != null) {
373
+ options.debug = process.env.DOTENV_CONFIG_DEBUG;
374
+ }
375
+ if (process.env.DOTENV_CONFIG_OVERRIDE != null) {
376
+ options.override = process.env.DOTENV_CONFIG_OVERRIDE;
377
+ }
378
+ if (process.env.DOTENV_CONFIG_DOTENV_KEY != null) {
379
+ options.DOTENV_KEY = process.env.DOTENV_CONFIG_DOTENV_KEY;
380
+ }
381
+ module.exports = options;
382
+ });
383
+
384
+ // ../../node_modules/dotenv/lib/cli-options.js
385
+ var require_cli_options = __commonJS((exports, module) => {
386
+ var re = /^dotenv_config_(encoding|path|debug|override|DOTENV_KEY)=(.+)$/;
387
+ module.exports = function optionMatcher(args) {
388
+ return args.reduce(function(acc, cur) {
389
+ const matches = cur.match(re);
390
+ if (matches) {
391
+ acc[matches[1]] = matches[2];
392
+ }
393
+ return acc;
394
+ }, {});
395
+ };
396
+ });
397
+
398
+ // ../../node_modules/dotenv/config.js
399
+ var require_config = __commonJS(() => {
400
+ (function() {
401
+ require_main().config(Object.assign({}, require_env_options(), require_cli_options()(process.argv)));
402
+ })();
403
+ });
404
+
31
405
  // ../../node_modules/commander/lib/error.js
32
406
  var require_error = __commonJS((exports) => {
33
407
  class CommanderError extends Error {
@@ -10184,7 +10558,7 @@ var require_on_exit_leak_free = __commonJS((exports, module) => {
10184
10558
  });
10185
10559
 
10186
10560
  // ../../node_modules/thread-stream/package.json
10187
- var require_package = __commonJS((exports, module) => {
10561
+ var require_package2 = __commonJS((exports, module) => {
10188
10562
  module.exports = {
10189
10563
  name: "thread-stream",
10190
10564
  version: "3.1.0",
@@ -10314,7 +10688,7 @@ var require_indexes = __commonJS((exports, module) => {
10314
10688
  // ../../node_modules/thread-stream/index.js
10315
10689
  var require_thread_stream = __commonJS((exports, module) => {
10316
10690
  var __dirname = "/Users/xiliangchen/projects/polka-codes/node_modules/thread-stream";
10317
- var { version } = require_package();
10691
+ var { version } = require_package2();
10318
10692
  var { EventEmitter } = __require("events");
10319
10693
  var { Worker } = __require("worker_threads");
10320
10694
  var { join } = __require("path");
@@ -19734,6 +20108,9 @@ var require_public_api2 = __commonJS((exports) => {
19734
20108
  exports.stringify = stringify2;
19735
20109
  });
19736
20110
 
20111
+ // src/index.ts
20112
+ var import_config2 = __toESM(require_config(), 1);
20113
+
19737
20114
  // ../../node_modules/commander/esm.mjs
19738
20115
  var import__ = __toESM(require_commander(), 1);
19739
20116
  var {
@@ -28032,7 +28409,7 @@ var attemptCompletion_default = {
28032
28409
  // ../core/src/tools/executeCommand.ts
28033
28410
  var toolInfo3 = {
28034
28411
  name: "execute_command",
28035
- description: `Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will be executed in the current working directory.`,
28412
+ description: `Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will also be executed in the project root directory regardless of executed commands in previous tool uses.`,
28036
28413
  parameters: [
28037
28414
  {
28038
28415
  name: "command",
@@ -28725,7 +29102,7 @@ class CoderAgent extends AgentBase {
28725
29102
  }
28726
29103
  }
28727
29104
  // package.json
28728
- var version = "0.2.0";
29105
+ var version = "0.3.0";
28729
29106
 
28730
29107
  // src/Chat.ts
28731
29108
  import readline from "node:readline";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "AGPL-3.0",
5
5
  "type": "module",
6
6
  "bin": {
@@ -18,6 +18,7 @@
18
18
  "dependencies": {
19
19
  "@polka-codes/core": "0.2.0",
20
20
  "commander": "^13.0.0",
21
+ "dotenv": "^16.4.7",
21
22
  "ignore": "^7.0.3",
22
23
  "pino-pretty": "^13.0.0",
23
24
  "yaml": "^2.7.0",