lendctl-ai 0.1.0 → 0.1.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.
package/bin/lendctl-ai ADDED
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ exec node "$(dirname "$0")/../dist/index.js" "$@"
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
- #!/usr/bin/env bun
2
- // @bun
1
+ #!/usr/bin/env node
3
2
  import { createRequire } from "node:module";
4
3
  var __create = Object.create;
5
4
  var __getProtoOf = Object.getPrototypeOf;
@@ -2212,6 +2211,152 @@ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
2212
2211
  return returnValue;
2213
2212
  }
2214
2213
 
2214
+ // node_modules/chalk/source/index.js
2215
+ function createChalk(options) {
2216
+ return chalkFactory(options);
2217
+ }
2218
+ var stdoutColor, stderrColor, GENERATOR, STYLER, IS_EMPTY, levelMapping, styles2, applyOptions = (object, options = {}) => {
2219
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
2220
+ throw new Error("The `level` option should be an integer from 0 to 3");
2221
+ }
2222
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
2223
+ object.level = options.level === undefined ? colorLevel : options.level;
2224
+ }, chalkFactory = (options) => {
2225
+ const chalk = (...strings) => strings.join(" ");
2226
+ applyOptions(chalk, options);
2227
+ Object.setPrototypeOf(chalk, createChalk.prototype);
2228
+ return chalk;
2229
+ }, getModelAnsi = (model, level, type, ...arguments_) => {
2230
+ if (model === "rgb") {
2231
+ if (level === "ansi16m") {
2232
+ return ansi_styles_default[type].ansi16m(...arguments_);
2233
+ }
2234
+ if (level === "ansi256") {
2235
+ return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
2236
+ }
2237
+ return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
2238
+ }
2239
+ if (model === "hex") {
2240
+ return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
2241
+ }
2242
+ return ansi_styles_default[type][model](...arguments_);
2243
+ }, usedModels, proto, createStyler = (open, close, parent) => {
2244
+ let openAll;
2245
+ let closeAll;
2246
+ if (parent === undefined) {
2247
+ openAll = open;
2248
+ closeAll = close;
2249
+ } else {
2250
+ openAll = parent.openAll + open;
2251
+ closeAll = close + parent.closeAll;
2252
+ }
2253
+ return {
2254
+ open,
2255
+ close,
2256
+ openAll,
2257
+ closeAll,
2258
+ parent
2259
+ };
2260
+ }, createBuilder = (self, _styler, _isEmpty) => {
2261
+ const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
2262
+ Object.setPrototypeOf(builder, proto);
2263
+ builder[GENERATOR] = self;
2264
+ builder[STYLER] = _styler;
2265
+ builder[IS_EMPTY] = _isEmpty;
2266
+ return builder;
2267
+ }, applyStyle = (self, string) => {
2268
+ if (self.level <= 0 || !string) {
2269
+ return self[IS_EMPTY] ? "" : string;
2270
+ }
2271
+ let styler = self[STYLER];
2272
+ if (styler === undefined) {
2273
+ return string;
2274
+ }
2275
+ const { openAll, closeAll } = styler;
2276
+ if (string.includes("\x1B")) {
2277
+ while (styler !== undefined) {
2278
+ string = stringReplaceAll(string, styler.close, styler.open);
2279
+ styler = styler.parent;
2280
+ }
2281
+ }
2282
+ const lfIndex = string.indexOf(`
2283
+ `);
2284
+ if (lfIndex !== -1) {
2285
+ string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
2286
+ }
2287
+ return openAll + string + closeAll;
2288
+ }, chalk, chalkStderr, source_default;
2289
+ var init_source = __esm(() => {
2290
+ init_ansi_styles();
2291
+ init_supports_color();
2292
+ ({ stdout: stdoutColor, stderr: stderrColor } = supports_color_default);
2293
+ GENERATOR = Symbol("GENERATOR");
2294
+ STYLER = Symbol("STYLER");
2295
+ IS_EMPTY = Symbol("IS_EMPTY");
2296
+ levelMapping = [
2297
+ "ansi",
2298
+ "ansi",
2299
+ "ansi256",
2300
+ "ansi16m"
2301
+ ];
2302
+ styles2 = Object.create(null);
2303
+ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
2304
+ for (const [styleName, style] of Object.entries(ansi_styles_default)) {
2305
+ styles2[styleName] = {
2306
+ get() {
2307
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
2308
+ Object.defineProperty(this, styleName, { value: builder });
2309
+ return builder;
2310
+ }
2311
+ };
2312
+ }
2313
+ styles2.visible = {
2314
+ get() {
2315
+ const builder = createBuilder(this, this[STYLER], true);
2316
+ Object.defineProperty(this, "visible", { value: builder });
2317
+ return builder;
2318
+ }
2319
+ };
2320
+ usedModels = ["rgb", "hex", "ansi256"];
2321
+ for (const model of usedModels) {
2322
+ styles2[model] = {
2323
+ get() {
2324
+ const { level } = this;
2325
+ return function(...arguments_) {
2326
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
2327
+ return createBuilder(this, styler, this[IS_EMPTY]);
2328
+ };
2329
+ }
2330
+ };
2331
+ const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
2332
+ styles2[bgModel] = {
2333
+ get() {
2334
+ const { level } = this;
2335
+ return function(...arguments_) {
2336
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
2337
+ return createBuilder(this, styler, this[IS_EMPTY]);
2338
+ };
2339
+ }
2340
+ };
2341
+ }
2342
+ proto = Object.defineProperties(() => {}, {
2343
+ ...styles2,
2344
+ level: {
2345
+ enumerable: true,
2346
+ get() {
2347
+ return this[GENERATOR].level;
2348
+ },
2349
+ set(level) {
2350
+ this[GENERATOR].level = level;
2351
+ }
2352
+ }
2353
+ });
2354
+ Object.defineProperties(createChalk.prototype, styles2);
2355
+ chalk = createChalk();
2356
+ chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
2357
+ source_default = chalk;
2358
+ });
2359
+
2215
2360
  // node_modules/yoctocolors-cjs/index.js
2216
2361
  var require_yoctocolors_cjs = __commonJS((exports, module) => {
2217
2362
  var tty2 = __require("node:tty");
@@ -21667,130 +21812,291 @@ var init_reporter = __esm(() => {
21667
21812
  init_dist5();
21668
21813
  });
21669
21814
 
21670
- // node_modules/dotenv/package.json
21671
- var require_package = __commonJS((exports, module) => {
21672
- module.exports = {
21673
- name: "dotenv",
21674
- version: "16.6.1",
21675
- description: "Loads environment variables from .env file",
21676
- main: "lib/main.js",
21677
- types: "lib/main.d.ts",
21678
- exports: {
21679
- ".": {
21680
- types: "./lib/main.d.ts",
21681
- require: "./lib/main.js",
21682
- default: "./lib/main.js"
21683
- },
21684
- "./config": "./config.js",
21685
- "./config.js": "./config.js",
21686
- "./lib/env-options": "./lib/env-options.js",
21687
- "./lib/env-options.js": "./lib/env-options.js",
21688
- "./lib/cli-options": "./lib/cli-options.js",
21689
- "./lib/cli-options.js": "./lib/cli-options.js",
21690
- "./package.json": "./package.json"
21691
- },
21692
- scripts: {
21693
- "dts-check": "tsc --project tests/types/tsconfig.json",
21694
- lint: "standard",
21695
- pretest: "npm run lint && npm run dts-check",
21696
- test: "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
21697
- "test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=text --coverage-report=lcov",
21698
- prerelease: "npm test",
21699
- release: "standard-version"
21700
- },
21701
- repository: {
21702
- type: "git",
21703
- url: "git://github.com/motdotla/dotenv.git"
21704
- },
21705
- homepage: "https://github.com/motdotla/dotenv#readme",
21706
- funding: "https://dotenvx.com",
21707
- keywords: [
21708
- "dotenv",
21709
- "env",
21710
- ".env",
21711
- "environment",
21712
- "variables",
21713
- "config",
21714
- "settings"
21715
- ],
21716
- readmeFilename: "README.md",
21717
- license: "BSD-2-Clause",
21718
- devDependencies: {
21719
- "@types/node": "^18.11.3",
21720
- decache: "^4.6.2",
21721
- sinon: "^14.0.1",
21722
- standard: "^17.0.0",
21723
- "standard-version": "^9.5.0",
21724
- tap: "^19.2.0",
21725
- typescript: "^4.8.4"
21726
- },
21727
- engines: {
21728
- node: ">=12"
21729
- },
21730
- browser: {
21731
- fs: false
21732
- }
21733
- };
21734
- });
21815
+ // src/agent/index.ts
21816
+ function generateSessionId() {
21817
+ const timestamp = Date.now().toString(36);
21818
+ const random = Math.random().toString(36).substring(2, 8);
21819
+ return `lendctl-${timestamp}-${random}`;
21820
+ }
21735
21821
 
21736
- // node_modules/dotenv/lib/main.js
21737
- var require_main = __commonJS((exports, module) => {
21738
- var fs = __require("fs");
21739
- var path = __require("path");
21740
- var os2 = __require("os");
21741
- var crypto = __require("crypto");
21742
- var packageJson = require_package();
21743
- var version = packageJson.version;
21744
- var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
21745
- function parse(src) {
21746
- const obj = {};
21747
- let lines = src.toString();
21748
- lines = lines.replace(/\r\n?/mg, `
21749
- `);
21750
- let match;
21751
- while ((match = LINE.exec(lines)) != null) {
21752
- const key = match[1];
21753
- let value = match[2] || "";
21754
- value = value.trim();
21755
- const maybeQuote = value[0];
21756
- value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
21757
- if (maybeQuote === '"') {
21758
- value = value.replace(/\\n/g, `
21759
- `);
21760
- value = value.replace(/\\r/g, "\r");
21761
- }
21762
- obj[key] = value;
21763
- }
21764
- return obj;
21822
+ class LendCtlAgent {
21823
+ sessionId;
21824
+ options;
21825
+ constructor(options = {}) {
21826
+ this.sessionId = generateSessionId();
21827
+ this.options = {
21828
+ model: options.model ?? "gpt-4o",
21829
+ maxIterations: options.maxIterations ?? 3,
21830
+ stream: options.stream ?? false,
21831
+ verbose: options.verbose ?? false,
21832
+ skipLLMValidation: options.skipLLMValidation ?? false
21833
+ };
21765
21834
  }
21766
- function _parseVault(options) {
21767
- options = options || {};
21768
- const vaultPath = _vaultPath(options);
21769
- options.path = vaultPath;
21770
- const result = DotenvModule.configDotenv(options);
21771
- if (!result.parsed) {
21772
- const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
21773
- err.code = "MISSING_DATA";
21774
- throw err;
21775
- }
21776
- const keys = _dotenvKey(options).split(",");
21777
- const length = keys.length;
21778
- let decrypted;
21779
- for (let i = 0;i < length; i++) {
21780
- try {
21781
- const key = keys[i].trim();
21782
- const attrs = _instructions(result, key);
21783
- decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
21784
- break;
21785
- } catch (error) {
21786
- if (i + 1 >= length) {
21787
- throw error;
21788
- }
21789
- }
21835
+ getSessionId() {
21836
+ return this.sessionId;
21837
+ }
21838
+ log(message) {
21839
+ if (this.options.verbose) {
21840
+ console.log(`[${this.sessionId}] ${message}`);
21790
21841
  }
21791
- return DotenvModule.parse(decrypted);
21792
21842
  }
21793
- function _warn(message) {
21843
+ async query(input, context, reportOptions) {
21844
+ const startTime = Date.now();
21845
+ let iteration = 0;
21846
+ let plan = null;
21847
+ let executionResult = null;
21848
+ let validation = null;
21849
+ let previousIssues = [];
21850
+ await logAuditEntry(this.sessionId, "query", {
21851
+ input,
21852
+ context,
21853
+ options: this.options
21854
+ });
21855
+ this.log(`Starting analysis: "${input.substring(0, 50)}..."`);
21856
+ while (iteration < this.options.maxIterations) {
21857
+ iteration++;
21858
+ this.log(`
21859
+ === Iteration ${iteration}/${this.options.maxIterations} ===`);
21860
+ this.log("Planning...");
21861
+ try {
21862
+ if (iteration === 1) {
21863
+ plan = await createPlan(input, context, this.options.model);
21864
+ } else if (plan && previousIssues.length > 0) {
21865
+ plan = await replan(input, plan, previousIssues, this.options.model);
21866
+ }
21867
+ } catch (error) {
21868
+ this.log(`Planning failed: ${error.message}`);
21869
+ await logAuditEntry(this.sessionId, "planning_failed", { error: error.message, iteration });
21870
+ throw error;
21871
+ }
21872
+ if (!plan) {
21873
+ throw new Error("Failed to create plan");
21874
+ }
21875
+ this.log(`Plan created with ${plan.steps.length} steps`);
21876
+ await logAuditEntry(this.sessionId, "plan_created", {
21877
+ iteration,
21878
+ steps: plan.steps.length,
21879
+ understanding: plan.understanding
21880
+ });
21881
+ this.log("Executing...");
21882
+ try {
21883
+ executionResult = await executePlan(plan, this.sessionId);
21884
+ } catch (error) {
21885
+ this.log(`Execution failed: ${error.message}`);
21886
+ await logAuditEntry(this.sessionId, "execution_failed", { error: error.message, iteration });
21887
+ throw error;
21888
+ }
21889
+ this.log(`Executed ${executionResult.steps.length} steps (${executionResult.failedSteps.length} failed)`);
21890
+ this.log("Validating...");
21891
+ try {
21892
+ validation = await validateResults(input, plan, executionResult.steps, {
21893
+ model: this.options.model,
21894
+ skipLLM: this.options.skipLLMValidation
21895
+ });
21896
+ } catch (error) {
21897
+ this.log(`Validation failed: ${error.message}`);
21898
+ validation = {
21899
+ isValid: false,
21900
+ issues: [{ severity: "error", message: `Validation error: ${error.message}` }],
21901
+ suggestions: [],
21902
+ complianceFlags: []
21903
+ };
21904
+ }
21905
+ this.log(`Validation: ${validation.isValid ? "PASSED" : "FAILED"} (${validation.issues.length} issues)`);
21906
+ await logAuditEntry(this.sessionId, "validation_complete", {
21907
+ iteration,
21908
+ isValid: validation.isValid,
21909
+ issueCount: validation.issues.length
21910
+ });
21911
+ if (validation.isValid) {
21912
+ this.log("✓ Validation passed");
21913
+ break;
21914
+ }
21915
+ const errorIssues = validation.issues.filter((i) => i.severity === "error").map((i) => i.message);
21916
+ if (errorIssues.length === 0) {
21917
+ this.log("⚠ Only warnings found, proceeding");
21918
+ break;
21919
+ }
21920
+ if (iteration < this.options.maxIterations) {
21921
+ this.log(`✗ Errors found, replanning...`);
21922
+ previousIssues = errorIssues;
21923
+ }
21924
+ }
21925
+ if (!plan || !executionResult || !validation) {
21926
+ throw new Error("Analysis incomplete");
21927
+ }
21928
+ this.log("Generating report...");
21929
+ const report = await generateReport(input, plan, executionResult.steps, validation, {
21930
+ model: this.options.model,
21931
+ stream: this.options.stream,
21932
+ ...reportOptions
21933
+ });
21934
+ const totalDurationMs = Date.now() - startTime;
21935
+ await logAuditEntry(this.sessionId, "analysis_complete", {
21936
+ iterations: iteration,
21937
+ totalDurationMs,
21938
+ success: validation.isValid || validation.issues.every((i) => i.severity !== "error")
21939
+ }, validation.isValid ? "approved" : "review_required", plan.understanding);
21940
+ this.log(`
21941
+ Analysis complete in ${totalDurationMs}ms (${iteration} iterations)`);
21942
+ return {
21943
+ sessionId: this.sessionId,
21944
+ plan,
21945
+ results: executionResult.steps,
21946
+ validation,
21947
+ report,
21948
+ iterations: iteration,
21949
+ totalDurationMs,
21950
+ success: validation.isValid || validation.issues.every((i) => i.severity !== "error")
21951
+ };
21952
+ }
21953
+ async quickQuery(input, context) {
21954
+ const plan = await createPlan(input, context, this.options.model);
21955
+ const executionResult = await executePlan(plan, this.sessionId);
21956
+ const validation = await validateResults(input, plan, executionResult.steps, {
21957
+ skipLLM: true
21958
+ });
21959
+ const summary = generateQuickSummary(executionResult.steps, validation);
21960
+ return {
21961
+ sessionId: this.sessionId,
21962
+ summary,
21963
+ results: executionResult.steps,
21964
+ validation
21965
+ };
21966
+ }
21967
+ }
21968
+ var init_agent = __esm(() => {
21969
+ init_planner();
21970
+ init_executor();
21971
+ init_validator();
21972
+ init_reporter();
21973
+ init_auditctl();
21974
+ });
21975
+
21976
+ // node_modules/dotenv/package.json
21977
+ var require_package = __commonJS((exports, module) => {
21978
+ module.exports = {
21979
+ name: "dotenv",
21980
+ version: "16.6.1",
21981
+ description: "Loads environment variables from .env file",
21982
+ main: "lib/main.js",
21983
+ types: "lib/main.d.ts",
21984
+ exports: {
21985
+ ".": {
21986
+ types: "./lib/main.d.ts",
21987
+ require: "./lib/main.js",
21988
+ default: "./lib/main.js"
21989
+ },
21990
+ "./config": "./config.js",
21991
+ "./config.js": "./config.js",
21992
+ "./lib/env-options": "./lib/env-options.js",
21993
+ "./lib/env-options.js": "./lib/env-options.js",
21994
+ "./lib/cli-options": "./lib/cli-options.js",
21995
+ "./lib/cli-options.js": "./lib/cli-options.js",
21996
+ "./package.json": "./package.json"
21997
+ },
21998
+ scripts: {
21999
+ "dts-check": "tsc --project tests/types/tsconfig.json",
22000
+ lint: "standard",
22001
+ pretest: "npm run lint && npm run dts-check",
22002
+ test: "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
22003
+ "test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=text --coverage-report=lcov",
22004
+ prerelease: "npm test",
22005
+ release: "standard-version"
22006
+ },
22007
+ repository: {
22008
+ type: "git",
22009
+ url: "git://github.com/motdotla/dotenv.git"
22010
+ },
22011
+ homepage: "https://github.com/motdotla/dotenv#readme",
22012
+ funding: "https://dotenvx.com",
22013
+ keywords: [
22014
+ "dotenv",
22015
+ "env",
22016
+ ".env",
22017
+ "environment",
22018
+ "variables",
22019
+ "config",
22020
+ "settings"
22021
+ ],
22022
+ readmeFilename: "README.md",
22023
+ license: "BSD-2-Clause",
22024
+ devDependencies: {
22025
+ "@types/node": "^18.11.3",
22026
+ decache: "^4.6.2",
22027
+ sinon: "^14.0.1",
22028
+ standard: "^17.0.0",
22029
+ "standard-version": "^9.5.0",
22030
+ tap: "^19.2.0",
22031
+ typescript: "^4.8.4"
22032
+ },
22033
+ engines: {
22034
+ node: ">=12"
22035
+ },
22036
+ browser: {
22037
+ fs: false
22038
+ }
22039
+ };
22040
+ });
22041
+
22042
+ // node_modules/dotenv/lib/main.js
22043
+ var require_main = __commonJS((exports, module) => {
22044
+ var fs = __require("fs");
22045
+ var path = __require("path");
22046
+ var os2 = __require("os");
22047
+ var crypto = __require("crypto");
22048
+ var packageJson = require_package();
22049
+ var version = packageJson.version;
22050
+ var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
22051
+ function parse(src) {
22052
+ const obj = {};
22053
+ let lines = src.toString();
22054
+ lines = lines.replace(/\r\n?/mg, `
22055
+ `);
22056
+ let match;
22057
+ while ((match = LINE.exec(lines)) != null) {
22058
+ const key = match[1];
22059
+ let value = match[2] || "";
22060
+ value = value.trim();
22061
+ const maybeQuote = value[0];
22062
+ value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
22063
+ if (maybeQuote === '"') {
22064
+ value = value.replace(/\\n/g, `
22065
+ `);
22066
+ value = value.replace(/\\r/g, "\r");
22067
+ }
22068
+ obj[key] = value;
22069
+ }
22070
+ return obj;
22071
+ }
22072
+ function _parseVault(options) {
22073
+ options = options || {};
22074
+ const vaultPath = _vaultPath(options);
22075
+ options.path = vaultPath;
22076
+ const result = DotenvModule.configDotenv(options);
22077
+ if (!result.parsed) {
22078
+ const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
22079
+ err.code = "MISSING_DATA";
22080
+ throw err;
22081
+ }
22082
+ const keys = _dotenvKey(options).split(",");
22083
+ const length = keys.length;
22084
+ let decrypted;
22085
+ for (let i = 0;i < length; i++) {
22086
+ try {
22087
+ const key = keys[i].trim();
22088
+ const attrs = _instructions(result, key);
22089
+ decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
22090
+ break;
22091
+ } catch (error) {
22092
+ if (i + 1 >= length) {
22093
+ throw error;
22094
+ }
22095
+ }
22096
+ }
22097
+ return DotenvModule.parse(decrypted);
22098
+ }
22099
+ function _warn(message) {
21794
22100
  console.log(`[dotenv@${version}][WARN] ${message}`);
21795
22101
  }
21796
22102
  function _debug(message) {
@@ -23922,167 +24228,6 @@ var init_streaming = __esm(() => {
23922
24228
  init_text();
23923
24229
  });
23924
24230
 
23925
- // src/agent/index.ts
23926
- function generateSessionId2() {
23927
- const timestamp = Date.now().toString(36);
23928
- const random = Math.random().toString(36).substring(2, 8);
23929
- return `lendctl-${timestamp}-${random}`;
23930
- }
23931
-
23932
- class LendCtlAgent2 {
23933
- sessionId;
23934
- options;
23935
- constructor(options = {}) {
23936
- this.sessionId = generateSessionId2();
23937
- this.options = {
23938
- model: options.model ?? "gpt-4o",
23939
- maxIterations: options.maxIterations ?? 3,
23940
- stream: options.stream ?? false,
23941
- verbose: options.verbose ?? false,
23942
- skipLLMValidation: options.skipLLMValidation ?? false
23943
- };
23944
- }
23945
- getSessionId() {
23946
- return this.sessionId;
23947
- }
23948
- log(message) {
23949
- if (this.options.verbose) {
23950
- console.log(`[${this.sessionId}] ${message}`);
23951
- }
23952
- }
23953
- async query(input, context, reportOptions) {
23954
- const startTime = Date.now();
23955
- let iteration = 0;
23956
- let plan = null;
23957
- let executionResult = null;
23958
- let validation = null;
23959
- let previousIssues = [];
23960
- await logAuditEntry(this.sessionId, "query", {
23961
- input,
23962
- context,
23963
- options: this.options
23964
- });
23965
- this.log(`Starting analysis: "${input.substring(0, 50)}..."`);
23966
- while (iteration < this.options.maxIterations) {
23967
- iteration++;
23968
- this.log(`
23969
- === Iteration ${iteration}/${this.options.maxIterations} ===`);
23970
- this.log("Planning...");
23971
- try {
23972
- if (iteration === 1) {
23973
- plan = await createPlan(input, context, this.options.model);
23974
- } else if (plan && previousIssues.length > 0) {
23975
- plan = await replan(input, plan, previousIssues, this.options.model);
23976
- }
23977
- } catch (error) {
23978
- this.log(`Planning failed: ${error.message}`);
23979
- await logAuditEntry(this.sessionId, "planning_failed", { error: error.message, iteration });
23980
- throw error;
23981
- }
23982
- if (!plan) {
23983
- throw new Error("Failed to create plan");
23984
- }
23985
- this.log(`Plan created with ${plan.steps.length} steps`);
23986
- await logAuditEntry(this.sessionId, "plan_created", {
23987
- iteration,
23988
- steps: plan.steps.length,
23989
- understanding: plan.understanding
23990
- });
23991
- this.log("Executing...");
23992
- try {
23993
- executionResult = await executePlan(plan, this.sessionId);
23994
- } catch (error) {
23995
- this.log(`Execution failed: ${error.message}`);
23996
- await logAuditEntry(this.sessionId, "execution_failed", { error: error.message, iteration });
23997
- throw error;
23998
- }
23999
- this.log(`Executed ${executionResult.steps.length} steps (${executionResult.failedSteps.length} failed)`);
24000
- this.log("Validating...");
24001
- try {
24002
- validation = await validateResults(input, plan, executionResult.steps, {
24003
- model: this.options.model,
24004
- skipLLM: this.options.skipLLMValidation
24005
- });
24006
- } catch (error) {
24007
- this.log(`Validation failed: ${error.message}`);
24008
- validation = {
24009
- isValid: false,
24010
- issues: [{ severity: "error", message: `Validation error: ${error.message}` }],
24011
- suggestions: [],
24012
- complianceFlags: []
24013
- };
24014
- }
24015
- this.log(`Validation: ${validation.isValid ? "PASSED" : "FAILED"} (${validation.issues.length} issues)`);
24016
- await logAuditEntry(this.sessionId, "validation_complete", {
24017
- iteration,
24018
- isValid: validation.isValid,
24019
- issueCount: validation.issues.length
24020
- });
24021
- if (validation.isValid) {
24022
- this.log("✓ Validation passed");
24023
- break;
24024
- }
24025
- const errorIssues = validation.issues.filter((i) => i.severity === "error").map((i) => i.message);
24026
- if (errorIssues.length === 0) {
24027
- this.log("⚠ Only warnings found, proceeding");
24028
- break;
24029
- }
24030
- if (iteration < this.options.maxIterations) {
24031
- this.log(`✗ Errors found, replanning...`);
24032
- previousIssues = errorIssues;
24033
- }
24034
- }
24035
- if (!plan || !executionResult || !validation) {
24036
- throw new Error("Analysis incomplete");
24037
- }
24038
- this.log("Generating report...");
24039
- const report = await generateReport(input, plan, executionResult.steps, validation, {
24040
- model: this.options.model,
24041
- stream: this.options.stream,
24042
- ...reportOptions
24043
- });
24044
- const totalDurationMs = Date.now() - startTime;
24045
- await logAuditEntry(this.sessionId, "analysis_complete", {
24046
- iterations: iteration,
24047
- totalDurationMs,
24048
- success: validation.isValid || validation.issues.every((i) => i.severity !== "error")
24049
- }, validation.isValid ? "approved" : "review_required", plan.understanding);
24050
- this.log(`
24051
- Analysis complete in ${totalDurationMs}ms (${iteration} iterations)`);
24052
- return {
24053
- sessionId: this.sessionId,
24054
- plan,
24055
- results: executionResult.steps,
24056
- validation,
24057
- report,
24058
- iterations: iteration,
24059
- totalDurationMs,
24060
- success: validation.isValid || validation.issues.every((i) => i.severity !== "error")
24061
- };
24062
- }
24063
- async quickQuery(input, context) {
24064
- const plan = await createPlan(input, context, this.options.model);
24065
- const executionResult = await executePlan(plan, this.sessionId);
24066
- const validation = await validateResults(input, plan, executionResult.steps, {
24067
- skipLLM: true
24068
- });
24069
- const summary = generateQuickSummary(executionResult.steps, validation);
24070
- return {
24071
- sessionId: this.sessionId,
24072
- summary,
24073
- results: executionResult.steps,
24074
- validation
24075
- };
24076
- }
24077
- }
24078
- var init_agent = __esm(() => {
24079
- init_planner();
24080
- init_executor();
24081
- init_validator();
24082
- init_reporter();
24083
- init_auditctl();
24084
- });
24085
-
24086
24231
  // src/server.ts
24087
24232
  var exports_server = {};
24088
24233
  __export(exports_server, {
@@ -24111,7 +24256,7 @@ var init_server = __esm(() => {
24111
24256
  if (!question) {
24112
24257
  return c.json({ error: "Missing required field: question" }, 400);
24113
24258
  }
24114
- const agent = new LendCtlAgent2({
24259
+ const agent = new LendCtlAgent({
24115
24260
  model: model || "gpt-4o",
24116
24261
  stream: stream2 || false
24117
24262
  });
@@ -24213,7 +24358,7 @@ var init_server = __esm(() => {
24213
24358
  if (!question) {
24214
24359
  return c.json({ error: "Missing required field: question" }, 400);
24215
24360
  }
24216
- const agent = new LendCtlAgent2({ model: model || "gpt-4o" });
24361
+ const agent = new LendCtlAgent({ model: model || "gpt-4o" });
24217
24362
  const result = await agent.quickQuery(question, context);
24218
24363
  return c.json({
24219
24364
  sessionId: result.sessionId,
@@ -24252,156 +24397,10 @@ var init_server = __esm(() => {
24252
24397
  format
24253
24398
  });
24254
24399
  });
24255
- server_default = {
24256
- port: parseInt(process.env.PORT || "5055"),
24257
- fetch: app.fetch
24258
- };
24259
- });
24260
-
24261
- // node_modules/chalk/source/index.js
24262
- function createChalk2(options) {
24263
- return chalkFactory2(options);
24264
- }
24265
- var stdoutColor2, stderrColor2, GENERATOR2, STYLER2, IS_EMPTY2, levelMapping2, styles3, applyOptions2 = (object3, options = {}) => {
24266
- if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
24267
- throw new Error("The `level` option should be an integer from 0 to 3");
24268
- }
24269
- const colorLevel = stdoutColor2 ? stdoutColor2.level : 0;
24270
- object3.level = options.level === undefined ? colorLevel : options.level;
24271
- }, chalkFactory2 = (options) => {
24272
- const chalk2 = (...strings) => strings.join(" ");
24273
- applyOptions2(chalk2, options);
24274
- Object.setPrototypeOf(chalk2, createChalk2.prototype);
24275
- return chalk2;
24276
- }, getModelAnsi2 = (model, level, type, ...arguments_) => {
24277
- if (model === "rgb") {
24278
- if (level === "ansi16m") {
24279
- return ansi_styles_default[type].ansi16m(...arguments_);
24280
- }
24281
- if (level === "ansi256") {
24282
- return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
24283
- }
24284
- return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
24285
- }
24286
- if (model === "hex") {
24287
- return getModelAnsi2("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
24288
- }
24289
- return ansi_styles_default[type][model](...arguments_);
24290
- }, usedModels2, proto2, createStyler2 = (open, close, parent) => {
24291
- let openAll;
24292
- let closeAll;
24293
- if (parent === undefined) {
24294
- openAll = open;
24295
- closeAll = close;
24296
- } else {
24297
- openAll = parent.openAll + open;
24298
- closeAll = close + parent.closeAll;
24299
- }
24300
- return {
24301
- open,
24302
- close,
24303
- openAll,
24304
- closeAll,
24305
- parent
24306
- };
24307
- }, createBuilder2 = (self, _styler, _isEmpty) => {
24308
- const builder = (...arguments_) => applyStyle2(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
24309
- Object.setPrototypeOf(builder, proto2);
24310
- builder[GENERATOR2] = self;
24311
- builder[STYLER2] = _styler;
24312
- builder[IS_EMPTY2] = _isEmpty;
24313
- return builder;
24314
- }, applyStyle2 = (self, string2) => {
24315
- if (self.level <= 0 || !string2) {
24316
- return self[IS_EMPTY2] ? "" : string2;
24317
- }
24318
- let styler = self[STYLER2];
24319
- if (styler === undefined) {
24320
- return string2;
24321
- }
24322
- const { openAll, closeAll } = styler;
24323
- if (string2.includes("\x1B")) {
24324
- while (styler !== undefined) {
24325
- string2 = stringReplaceAll(string2, styler.close, styler.open);
24326
- styler = styler.parent;
24327
- }
24328
- }
24329
- const lfIndex = string2.indexOf(`
24330
- `);
24331
- if (lfIndex !== -1) {
24332
- string2 = stringEncaseCRLFWithFirstIndex(string2, closeAll, openAll, lfIndex);
24333
- }
24334
- return openAll + string2 + closeAll;
24335
- }, chalk2, chalkStderr2, source_default2;
24336
- var init_source = __esm(() => {
24337
- init_ansi_styles();
24338
- init_supports_color();
24339
- ({ stdout: stdoutColor2, stderr: stderrColor2 } = supports_color_default);
24340
- GENERATOR2 = Symbol("GENERATOR");
24341
- STYLER2 = Symbol("STYLER");
24342
- IS_EMPTY2 = Symbol("IS_EMPTY");
24343
- levelMapping2 = [
24344
- "ansi",
24345
- "ansi",
24346
- "ansi256",
24347
- "ansi16m"
24348
- ];
24349
- styles3 = Object.create(null);
24350
- Object.setPrototypeOf(createChalk2.prototype, Function.prototype);
24351
- for (const [styleName, style] of Object.entries(ansi_styles_default)) {
24352
- styles3[styleName] = {
24353
- get() {
24354
- const builder = createBuilder2(this, createStyler2(style.open, style.close, this[STYLER2]), this[IS_EMPTY2]);
24355
- Object.defineProperty(this, styleName, { value: builder });
24356
- return builder;
24357
- }
24358
- };
24359
- }
24360
- styles3.visible = {
24361
- get() {
24362
- const builder = createBuilder2(this, this[STYLER2], true);
24363
- Object.defineProperty(this, "visible", { value: builder });
24364
- return builder;
24365
- }
24366
- };
24367
- usedModels2 = ["rgb", "hex", "ansi256"];
24368
- for (const model of usedModels2) {
24369
- styles3[model] = {
24370
- get() {
24371
- const { level } = this;
24372
- return function(...arguments_) {
24373
- const styler = createStyler2(getModelAnsi2(model, levelMapping2[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER2]);
24374
- return createBuilder2(this, styler, this[IS_EMPTY2]);
24375
- };
24376
- }
24377
- };
24378
- const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
24379
- styles3[bgModel] = {
24380
- get() {
24381
- const { level } = this;
24382
- return function(...arguments_) {
24383
- const styler = createStyler2(getModelAnsi2(model, levelMapping2[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER2]);
24384
- return createBuilder2(this, styler, this[IS_EMPTY2]);
24385
- };
24386
- }
24387
- };
24388
- }
24389
- proto2 = Object.defineProperties(() => {}, {
24390
- ...styles3,
24391
- level: {
24392
- enumerable: true,
24393
- get() {
24394
- return this[GENERATOR2].level;
24395
- },
24396
- set(level) {
24397
- this[GENERATOR2].level = level;
24398
- }
24399
- }
24400
- });
24401
- Object.defineProperties(createChalk2.prototype, styles3);
24402
- chalk2 = createChalk2();
24403
- chalkStderr2 = createChalk2({ level: stderrColor2 ? stderrColor2.level : 0 });
24404
- source_default2 = chalk2;
24400
+ server_default = {
24401
+ port: parseInt(process.env.PORT || "5055"),
24402
+ fetch: app.fetch
24403
+ };
24405
24404
  });
24406
24405
 
24407
24406
  // src/evals/run.ts
@@ -24411,16 +24410,16 @@ __export(exports_run, {
24411
24410
  });
24412
24411
  async function runEvals(sampleSize) {
24413
24412
  const cases = sampleSize ? TEST_CASES.sort(() => Math.random() - 0.5).slice(0, sampleSize) : TEST_CASES;
24414
- console.log(source_default2.cyan(`
24413
+ console.log(source_default.cyan(`
24415
24414
  Running ${cases.length} evaluation cases...
24416
24415
  `));
24417
24416
  let passed = 0;
24418
24417
  let failed = 0;
24419
24418
  for (const testCase of cases) {
24420
- console.log(source_default2.yellow(`\uD83D\uDCCB ${testCase.name}`));
24421
- console.log(source_default2.gray(` Query: "${testCase.query.substring(0, 60)}..."`));
24419
+ console.log(source_default.yellow(`\uD83D\uDCCB ${testCase.name}`));
24420
+ console.log(source_default.gray(` Query: "${testCase.query.substring(0, 60)}..."`));
24422
24421
  try {
24423
- const agent = new LendCtlAgent2({
24422
+ const agent = new LendCtlAgent({
24424
24423
  model: "gpt-4o-mini",
24425
24424
  skipLLMValidation: true
24426
24425
  });
@@ -24446,29 +24445,29 @@ Running ${cases.length} evaluation cases...
24446
24445
  }
24447
24446
  }
24448
24447
  if (passedChecks) {
24449
- console.log(source_default2.green(` ✓ PASSED`));
24448
+ console.log(source_default.green(` ✓ PASSED`));
24450
24449
  passed++;
24451
24450
  } else {
24452
- console.log(source_default2.red(` ✗ FAILED`));
24451
+ console.log(source_default.red(` ✗ FAILED`));
24453
24452
  for (const issue of issues) {
24454
- console.log(source_default2.red(` - ${issue}`));
24453
+ console.log(source_default.red(` - ${issue}`));
24455
24454
  }
24456
24455
  failed++;
24457
24456
  }
24458
24457
  } catch (error) {
24459
- console.log(source_default2.red(` ✗ ERROR: ${error.message}`));
24458
+ console.log(source_default.red(` ✗ ERROR: ${error.message}`));
24460
24459
  failed++;
24461
24460
  }
24462
24461
  console.log();
24463
24462
  }
24464
- console.log(source_default2.cyan("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
24465
- console.log(source_default2.bold(`
24463
+ console.log(source_default.cyan("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
24464
+ console.log(source_default.bold(`
24466
24465
  Results: ${passed}/${cases.length} passed`));
24467
24466
  if (failed === 0) {
24468
- console.log(source_default2.green(`
24467
+ console.log(source_default.green(`
24469
24468
  ✓ All tests passed!`));
24470
24469
  } else {
24471
- console.log(source_default2.red(`
24470
+ console.log(source_default.red(`
24472
24471
  ✗ ${failed} tests failed`));
24473
24472
  process.exit(1);
24474
24473
  }
@@ -24562,154 +24561,8 @@ var {
24562
24561
  Help
24563
24562
  } = import__.default;
24564
24563
 
24565
- // node_modules/chalk/source/index.js
24566
- init_ansi_styles();
24567
- init_supports_color();
24568
- var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
24569
- var GENERATOR = Symbol("GENERATOR");
24570
- var STYLER = Symbol("STYLER");
24571
- var IS_EMPTY = Symbol("IS_EMPTY");
24572
- var levelMapping = [
24573
- "ansi",
24574
- "ansi",
24575
- "ansi256",
24576
- "ansi16m"
24577
- ];
24578
- var styles2 = Object.create(null);
24579
- var applyOptions = (object, options = {}) => {
24580
- if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
24581
- throw new Error("The `level` option should be an integer from 0 to 3");
24582
- }
24583
- const colorLevel = stdoutColor ? stdoutColor.level : 0;
24584
- object.level = options.level === undefined ? colorLevel : options.level;
24585
- };
24586
- var chalkFactory = (options) => {
24587
- const chalk = (...strings) => strings.join(" ");
24588
- applyOptions(chalk, options);
24589
- Object.setPrototypeOf(chalk, createChalk.prototype);
24590
- return chalk;
24591
- };
24592
- function createChalk(options) {
24593
- return chalkFactory(options);
24594
- }
24595
- Object.setPrototypeOf(createChalk.prototype, Function.prototype);
24596
- for (const [styleName, style] of Object.entries(ansi_styles_default)) {
24597
- styles2[styleName] = {
24598
- get() {
24599
- const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
24600
- Object.defineProperty(this, styleName, { value: builder });
24601
- return builder;
24602
- }
24603
- };
24604
- }
24605
- styles2.visible = {
24606
- get() {
24607
- const builder = createBuilder(this, this[STYLER], true);
24608
- Object.defineProperty(this, "visible", { value: builder });
24609
- return builder;
24610
- }
24611
- };
24612
- var getModelAnsi = (model, level, type, ...arguments_) => {
24613
- if (model === "rgb") {
24614
- if (level === "ansi16m") {
24615
- return ansi_styles_default[type].ansi16m(...arguments_);
24616
- }
24617
- if (level === "ansi256") {
24618
- return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
24619
- }
24620
- return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
24621
- }
24622
- if (model === "hex") {
24623
- return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
24624
- }
24625
- return ansi_styles_default[type][model](...arguments_);
24626
- };
24627
- var usedModels = ["rgb", "hex", "ansi256"];
24628
- for (const model of usedModels) {
24629
- styles2[model] = {
24630
- get() {
24631
- const { level } = this;
24632
- return function(...arguments_) {
24633
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
24634
- return createBuilder(this, styler, this[IS_EMPTY]);
24635
- };
24636
- }
24637
- };
24638
- const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
24639
- styles2[bgModel] = {
24640
- get() {
24641
- const { level } = this;
24642
- return function(...arguments_) {
24643
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
24644
- return createBuilder(this, styler, this[IS_EMPTY]);
24645
- };
24646
- }
24647
- };
24648
- }
24649
- var proto = Object.defineProperties(() => {}, {
24650
- ...styles2,
24651
- level: {
24652
- enumerable: true,
24653
- get() {
24654
- return this[GENERATOR].level;
24655
- },
24656
- set(level) {
24657
- this[GENERATOR].level = level;
24658
- }
24659
- }
24660
- });
24661
- var createStyler = (open, close, parent) => {
24662
- let openAll;
24663
- let closeAll;
24664
- if (parent === undefined) {
24665
- openAll = open;
24666
- closeAll = close;
24667
- } else {
24668
- openAll = parent.openAll + open;
24669
- closeAll = close + parent.closeAll;
24670
- }
24671
- return {
24672
- open,
24673
- close,
24674
- openAll,
24675
- closeAll,
24676
- parent
24677
- };
24678
- };
24679
- var createBuilder = (self, _styler, _isEmpty) => {
24680
- const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
24681
- Object.setPrototypeOf(builder, proto);
24682
- builder[GENERATOR] = self;
24683
- builder[STYLER] = _styler;
24684
- builder[IS_EMPTY] = _isEmpty;
24685
- return builder;
24686
- };
24687
- var applyStyle = (self, string) => {
24688
- if (self.level <= 0 || !string) {
24689
- return self[IS_EMPTY] ? "" : string;
24690
- }
24691
- let styler = self[STYLER];
24692
- if (styler === undefined) {
24693
- return string;
24694
- }
24695
- const { openAll, closeAll } = styler;
24696
- if (string.includes("\x1B")) {
24697
- while (styler !== undefined) {
24698
- string = stringReplaceAll(string, styler.close, styler.open);
24699
- styler = styler.parent;
24700
- }
24701
- }
24702
- const lfIndex = string.indexOf(`
24703
- `);
24704
- if (lfIndex !== -1) {
24705
- string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
24706
- }
24707
- return openAll + string + closeAll;
24708
- };
24709
- Object.defineProperties(createChalk.prototype, styles2);
24710
- var chalk = createChalk();
24711
- var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
24712
- var source_default = chalk;
24564
+ // src/index.ts
24565
+ init_source();
24713
24566
 
24714
24567
  // node_modules/@inquirer/core/dist/esm/lib/key.js
24715
24568
  var isBackspaceKey = (key) => key.name === "backspace";
@@ -25766,175 +25619,17 @@ var esm_default2 = createPrompt((config, done) => {
25766
25619
  error
25767
25620
  ];
25768
25621
  });
25769
- // src/agent/index.ts
25770
- init_planner();
25771
- init_executor();
25772
- init_validator();
25773
- init_reporter();
25774
- init_auditctl();
25775
- function generateSessionId() {
25776
- const timestamp = Date.now().toString(36);
25777
- const random = Math.random().toString(36).substring(2, 8);
25778
- return `lendctl-${timestamp}-${random}`;
25779
- }
25780
-
25781
- class LendCtlAgent {
25782
- sessionId;
25783
- options;
25784
- constructor(options = {}) {
25785
- this.sessionId = generateSessionId();
25786
- this.options = {
25787
- model: options.model ?? "gpt-4o",
25788
- maxIterations: options.maxIterations ?? 3,
25789
- stream: options.stream ?? false,
25790
- verbose: options.verbose ?? false,
25791
- skipLLMValidation: options.skipLLMValidation ?? false
25792
- };
25793
- }
25794
- getSessionId() {
25795
- return this.sessionId;
25796
- }
25797
- log(message) {
25798
- if (this.options.verbose) {
25799
- console.log(`[${this.sessionId}] ${message}`);
25800
- }
25801
- }
25802
- async query(input, context, reportOptions) {
25803
- const startTime = Date.now();
25804
- let iteration = 0;
25805
- let plan = null;
25806
- let executionResult = null;
25807
- let validation = null;
25808
- let previousIssues = [];
25809
- await logAuditEntry(this.sessionId, "query", {
25810
- input,
25811
- context,
25812
- options: this.options
25813
- });
25814
- this.log(`Starting analysis: "${input.substring(0, 50)}..."`);
25815
- while (iteration < this.options.maxIterations) {
25816
- iteration++;
25817
- this.log(`
25818
- === Iteration ${iteration}/${this.options.maxIterations} ===`);
25819
- this.log("Planning...");
25820
- try {
25821
- if (iteration === 1) {
25822
- plan = await createPlan(input, context, this.options.model);
25823
- } else if (plan && previousIssues.length > 0) {
25824
- plan = await replan(input, plan, previousIssues, this.options.model);
25825
- }
25826
- } catch (error) {
25827
- this.log(`Planning failed: ${error.message}`);
25828
- await logAuditEntry(this.sessionId, "planning_failed", { error: error.message, iteration });
25829
- throw error;
25830
- }
25831
- if (!plan) {
25832
- throw new Error("Failed to create plan");
25833
- }
25834
- this.log(`Plan created with ${plan.steps.length} steps`);
25835
- await logAuditEntry(this.sessionId, "plan_created", {
25836
- iteration,
25837
- steps: plan.steps.length,
25838
- understanding: plan.understanding
25839
- });
25840
- this.log("Executing...");
25841
- try {
25842
- executionResult = await executePlan(plan, this.sessionId);
25843
- } catch (error) {
25844
- this.log(`Execution failed: ${error.message}`);
25845
- await logAuditEntry(this.sessionId, "execution_failed", { error: error.message, iteration });
25846
- throw error;
25847
- }
25848
- this.log(`Executed ${executionResult.steps.length} steps (${executionResult.failedSteps.length} failed)`);
25849
- this.log("Validating...");
25850
- try {
25851
- validation = await validateResults(input, plan, executionResult.steps, {
25852
- model: this.options.model,
25853
- skipLLM: this.options.skipLLMValidation
25854
- });
25855
- } catch (error) {
25856
- this.log(`Validation failed: ${error.message}`);
25857
- validation = {
25858
- isValid: false,
25859
- issues: [{ severity: "error", message: `Validation error: ${error.message}` }],
25860
- suggestions: [],
25861
- complianceFlags: []
25862
- };
25863
- }
25864
- this.log(`Validation: ${validation.isValid ? "PASSED" : "FAILED"} (${validation.issues.length} issues)`);
25865
- await logAuditEntry(this.sessionId, "validation_complete", {
25866
- iteration,
25867
- isValid: validation.isValid,
25868
- issueCount: validation.issues.length
25869
- });
25870
- if (validation.isValid) {
25871
- this.log("✓ Validation passed");
25872
- break;
25873
- }
25874
- const errorIssues = validation.issues.filter((i) => i.severity === "error").map((i) => i.message);
25875
- if (errorIssues.length === 0) {
25876
- this.log("⚠ Only warnings found, proceeding");
25877
- break;
25878
- }
25879
- if (iteration < this.options.maxIterations) {
25880
- this.log(`✗ Errors found, replanning...`);
25881
- previousIssues = errorIssues;
25882
- }
25883
- }
25884
- if (!plan || !executionResult || !validation) {
25885
- throw new Error("Analysis incomplete");
25886
- }
25887
- this.log("Generating report...");
25888
- const report = await generateReport(input, plan, executionResult.steps, validation, {
25889
- model: this.options.model,
25890
- stream: this.options.stream,
25891
- ...reportOptions
25892
- });
25893
- const totalDurationMs = Date.now() - startTime;
25894
- await logAuditEntry(this.sessionId, "analysis_complete", {
25895
- iterations: iteration,
25896
- totalDurationMs,
25897
- success: validation.isValid || validation.issues.every((i) => i.severity !== "error")
25898
- }, validation.isValid ? "approved" : "review_required", plan.understanding);
25899
- this.log(`
25900
- Analysis complete in ${totalDurationMs}ms (${iteration} iterations)`);
25901
- return {
25902
- sessionId: this.sessionId,
25903
- plan,
25904
- results: executionResult.steps,
25905
- validation,
25906
- report,
25907
- iterations: iteration,
25908
- totalDurationMs,
25909
- success: validation.isValid || validation.issues.every((i) => i.severity !== "error")
25910
- };
25911
- }
25912
- async quickQuery(input, context) {
25913
- const plan = await createPlan(input, context, this.options.model);
25914
- const executionResult = await executePlan(plan, this.sessionId);
25915
- const validation = await validateResults(input, plan, executionResult.steps, {
25916
- skipLLM: true
25917
- });
25918
- const summary = generateQuickSummary(executionResult.steps, validation);
25919
- return {
25920
- sessionId: this.sessionId,
25921
- summary,
25922
- results: executionResult.steps,
25923
- validation
25924
- };
25925
- }
25926
- }
25927
-
25928
25622
  // src/index.ts
25623
+ init_agent();
25929
25624
  var import_config = __toESM(require_config(), 1);
25930
25625
  var program2 = new Command;
25931
25626
  var banner = `
25932
- ${source_default.cyan("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557")}
25933
- ${source_default.cyan("\u2551")} ${source_default.bold.white("LendCtl AI")} - Autonomous Lending Decision Agent ${source_default.cyan("\u2551")}
25934
- ${source_default.cyan("\u2551")} ${source_default.gray("Powered by LendCtl CLI Suite")} ${source_default.cyan("\u2551")}
25935
- ${source_default.cyan("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D")}
25627
+ ${source_default.cyan("╔═══════════════════════════════════════════════════════════╗")}
25628
+ ${source_default.cyan("")} ${source_default.bold.white("LendCtl AI")} - Autonomous Lending Decision Agent ${source_default.cyan("")}
25629
+ ${source_default.cyan("")} ${source_default.gray("Powered by LendCtl CLI Suite")} ${source_default.cyan("")}
25630
+ ${source_default.cyan("╚═══════════════════════════════════════════════════════════╝")}
25936
25631
  `;
25937
- program2.name("lendctl-ai").description("Autonomous lending decision agent powered by LendCtl CLI suite").version("0.1.0");
25632
+ program2.name("lendctl-ai").description("Autonomous lending decision agent powered by LendCtl CLI suite").version("0.1.2");
25938
25633
  program2.command("ask").description("Ask a lending question").argument("<question>", "Your lending question").option("-m, --model <model>", "LLM model to use", "gpt-4o").option("-i, --iterations <n>", "Max planning iterations", "3").option("-v, --verbose", "Show detailed output").option("--quick", "Quick mode (skip LLM report generation)").action(async (question, options) => {
25939
25634
  console.log(banner);
25940
25635
  const agent = new LendCtlAgent({
@@ -25953,7 +25648,7 @@ program2.command("ask").description("Ask a lending question").argument("<questio
25953
25648
  console.log(source_default.gray(`
25954
25649
  Session: ${result.sessionId}`));
25955
25650
  } else {
25956
- const spinner = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
25651
+ const spinner = ["", "", "", "", "", "", "", "", "", ""];
25957
25652
  let i = 0;
25958
25653
  const spinnerInterval = setInterval(() => {
25959
25654
  process.stdout.write(`\r${source_default.cyan(spinner[i++ % spinner.length])} Analyzing...`);
@@ -25969,11 +25664,11 @@ Session: ${result.sessionId}`));
25969
25664
  console.log(source_default.yellow(`
25970
25665
  \uD83D\uDCCA Results:`));
25971
25666
  for (const step of result.results) {
25972
- const status = step.success ? source_default.green("\u2713") : source_default.red("\u2717");
25667
+ const status = step.success ? source_default.green("") : source_default.red("");
25973
25668
  console.log(` ${status} ${step.description} (${step.durationMs}ms)`);
25974
25669
  }
25975
25670
  console.log(source_default.yellow(`
25976
- \u2713 Validation:`));
25671
+ Validation:`));
25977
25672
  console.log(` Status: ${result.validation.isValid ? source_default.green("VALID") : source_default.red("INVALID")}`);
25978
25673
  if (result.validation.issues.length > 0) {
25979
25674
  for (const issue of result.validation.issues) {
@@ -25994,13 +25689,13 @@ Session: ${result.sessionId}`));
25994
25689
  console.log();
25995
25690
  }
25996
25691
  console.log(source_default.gray(`
25997
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`));
25692
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`));
25998
25693
  console.log(source_default.gray(`Session: ${result.sessionId}`));
25999
25694
  console.log(source_default.gray(`Iterations: ${result.iterations} | Time: ${result.totalDurationMs}ms`));
26000
25695
  }
26001
25696
  } catch (error) {
26002
25697
  console.error(source_default.red(`
26003
- \u274C Error: ${error.message}`));
25698
+ Error: ${error.message}`));
26004
25699
  if (options.verbose) {
26005
25700
  console.error(error.stack);
26006
25701
  }
@@ -26050,7 +25745,7 @@ program2.command("serve").description("Start the API server").option("-p, --port
26050
25745
  console.log(banner);
26051
25746
  console.log(source_default.cyan(`Starting API server on port ${options.port}...`));
26052
25747
  const { default: server } = await Promise.resolve().then(() => (init_server(), exports_server));
26053
- console.log(source_default.green(`\u2713 Server running at http://localhost:${options.port}`));
25748
+ console.log(source_default.green(`✓ Server running at http://localhost:${options.port}`));
26054
25749
  console.log(source_default.gray(`
26055
25750
  Endpoints:`));
26056
25751
  console.log(source_default.gray(" POST /api/v1/query - Submit a lending question"));
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "lendctl-ai",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Autonomous lending decision agent powered by LendCtl CLI suite",
5
5
  "author": "Satyan Avatara <rsatyan@gmail.com>",
6
6
  "license": "Apache-2.0",
7
7
  "type": "module",
8
8
  "bin": {
9
- "lendctl-ai": "./dist/index.js"
9
+ "lendctl-ai": "./bin/lendctl-ai"
10
10
  },
11
11
  "main": "./dist/index.js",
12
12
  "types": "./dist/index.d.ts",
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "files": [
24
24
  "dist",
25
+ "bin",
25
26
  "README.md",
26
27
  "LICENSE"
27
28
  ],