@riotprompt/riotprompt 0.0.20 → 0.0.21

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.
@@ -1,46 +1,26 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
- require("dotenv/config");
5
- const commander = require("commander");
6
- const cardigantime = require("@theunwalked/cardigantime");
7
- const zod = require("zod");
8
- const fs$1 = require("fs/promises");
9
- const path = require("path");
10
- require("zod-to-json-schema");
11
- const crypto = require("crypto");
12
- require("tiktoken");
13
- const fastXmlParser = require("fast-xml-parser");
14
- const OpenAI = require("openai");
15
- const Anthropic = require("@anthropic-ai/sdk");
16
- const generativeAi = require("@google/generative-ai");
17
- const fs = require("fs");
18
- const glob = require("glob");
19
- function _interopNamespaceDefault(e) {
20
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
21
- if (e) {
22
- for (const k in e) {
23
- if (k !== "default") {
24
- const d = Object.getOwnPropertyDescriptor(e, k);
25
- Object.defineProperty(n, k, d.get ? d : {
26
- enumerable: true,
27
- get: () => e[k]
28
- });
29
- }
30
- }
31
- }
32
- n.default = e;
33
- return Object.freeze(n);
34
- }
35
- const fs__namespace$1 = /* @__PURE__ */ _interopNamespaceDefault(fs$1);
36
- const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
37
- const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
38
- const ConfigSchema = zod.z.object({
39
- defaultModel: zod.z.string().default("gpt-4").describe("Default model to use for formatting"),
40
- promptsDir: zod.z.string().default(".").describe("Directory containing prompts"),
41
- outputDir: zod.z.string().optional().describe("Directory to output formatted prompts")
2
+ import "dotenv/config";
3
+ import { Command } from "commander";
4
+ import { create as create$7 } from "@theunwalked/cardigantime";
5
+ import { z } from "zod";
6
+ import * as path from "path";
7
+ import path__default from "path";
8
+ import "zod-to-json-schema";
9
+ import "tiktoken";
10
+ import { XMLParser } from "fast-xml-parser";
11
+ import OpenAI from "openai";
12
+ import Anthropic from "@anthropic-ai/sdk";
13
+ import { GoogleGenerativeAI } from "@google/generative-ai";
14
+ import { glob } from "glob";
15
+ import * as fs from "fs";
16
+ import crypto from "crypto";
17
+ import * as fs$1 from "fs/promises";
18
+ const ConfigSchema = z.object({
19
+ defaultModel: z.string().default("gpt-4").describe("Default model to use for formatting"),
20
+ promptsDir: z.string().default(".").describe("Directory containing prompts"),
21
+ outputDir: z.string().optional().describe("Directory to output formatted prompts")
42
22
  });
43
- const ParametersSchema = zod.z.record(zod.z.string(), zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.array(zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]))]));
23
+ const ParametersSchema = z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.union([z.string(), z.number(), z.boolean()]))]));
44
24
  const apply = (text, parameters) => {
45
25
  if (!parameters) {
46
26
  return text;
@@ -67,12 +47,12 @@ const apply = (text, parameters) => {
67
47
  }
68
48
  });
69
49
  };
70
- zod.z.object({
71
- text: zod.z.string(),
72
- weight: zod.z.number().optional()
50
+ z.object({
51
+ text: z.string(),
52
+ weight: z.number().optional()
73
53
  });
74
- const WeightedOptionsSchema = zod.z.object({
75
- weight: zod.z.number().optional(),
54
+ const WeightedOptionsSchema = z.object({
55
+ weight: z.number().optional(),
76
56
  parameters: ParametersSchema.optional()
77
57
  });
78
58
  const create$6 = (text, options = {}) => {
@@ -87,10 +67,10 @@ const create$5 = (text, options = {}) => {
87
67
  const weightedOptions = WeightedOptionsSchema.parse(options);
88
68
  return create$6(text, weightedOptions);
89
69
  };
90
- const SectionOptionsSchema = zod.z.object({
91
- title: zod.z.string().optional(),
92
- weight: zod.z.number().optional(),
93
- itemWeight: zod.z.number().optional(),
70
+ const SectionOptionsSchema = z.object({
71
+ title: z.string().optional(),
72
+ weight: z.number().optional(),
73
+ itemWeight: z.number().optional(),
94
74
  parameters: ParametersSchema.optional().default({})
95
75
  });
96
76
  const create$4 = (options = {}) => {
@@ -486,18 +466,18 @@ const stringifyJSON = function(obj, visited = /* @__PURE__ */ new Set()) {
486
466
  }
487
467
  return "";
488
468
  };
489
- const SectionSeparatorSchema = zod.z.enum(["tag", "markdown"]);
490
- const SectionTitlePropertySchema = zod.z.enum(["title", "name"]);
491
- const FormatOptionsSchema = zod.z.object({
469
+ const SectionSeparatorSchema = z.enum(["tag", "markdown"]);
470
+ const SectionTitlePropertySchema = z.enum(["title", "name"]);
471
+ const FormatOptionsSchema = z.object({
492
472
  sectionSeparator: SectionSeparatorSchema,
493
- sectionIndentation: zod.z.boolean(),
473
+ sectionIndentation: z.boolean(),
494
474
  sectionTitleProperty: SectionTitlePropertySchema,
495
- sectionTitlePrefix: zod.z.string().optional(),
496
- sectionTitleSeparator: zod.z.string().optional(),
497
- sectionDepth: zod.z.number().default(0)
475
+ sectionTitlePrefix: z.string().optional(),
476
+ sectionTitleSeparator: z.string().optional(),
477
+ sectionDepth: z.number().default(0)
498
478
  });
499
- const OptionSchema = zod.z.object({
500
- logger: zod.z.any().optional().default(DEFAULT_LOGGER),
479
+ const OptionSchema = z.object({
480
+ logger: z.any().optional().default(DEFAULT_LOGGER),
501
481
  formatOptions: FormatOptionsSchema.partial().optional().default(DEFAULT_FORMAT_OPTIONS)
502
482
  });
503
483
  function isSection(obj) {
@@ -622,22 +602,22 @@ ${formattedItems}`;
622
602
  formatArray
623
603
  };
624
604
  };
625
- zod.z.object({
626
- logger: zod.z.any().optional().default(DEFAULT_LOGGER),
605
+ z.object({
606
+ logger: z.any().optional().default(DEFAULT_LOGGER),
627
607
  parameters: ParametersSchema.optional().default({})
628
608
  });
629
609
  const create$1 = (params) => {
630
610
  const log = params.log || console.log;
631
611
  const exists = async (path2) => {
632
612
  try {
633
- await fs__namespace.promises.stat(path2);
613
+ await fs.promises.stat(path2);
634
614
  return true;
635
615
  } catch (error) {
636
616
  return false;
637
617
  }
638
618
  };
639
619
  const isDirectory2 = async (path2) => {
640
- const stats = await fs__namespace.promises.stat(path2);
620
+ const stats = await fs.promises.stat(path2);
641
621
  if (!stats.isDirectory()) {
642
622
  log(`${path2} is not a directory`);
643
623
  return false;
@@ -645,7 +625,7 @@ const create$1 = (params) => {
645
625
  return true;
646
626
  };
647
627
  const isFile = async (path2) => {
648
- const stats = await fs__namespace.promises.stat(path2);
628
+ const stats = await fs.promises.stat(path2);
649
629
  if (!stats.isFile()) {
650
630
  log(`${path2} is not a file`);
651
631
  return false;
@@ -654,7 +634,7 @@ const create$1 = (params) => {
654
634
  };
655
635
  const isReadable = async (path2) => {
656
636
  try {
657
- await fs__namespace.promises.access(path2, fs__namespace.constants.R_OK);
637
+ await fs.promises.access(path2, fs.constants.R_OK);
658
638
  } catch (error) {
659
639
  log(`${path2} is not readable: %s %s`, error.message, error.stack);
660
640
  return false;
@@ -663,7 +643,7 @@ const create$1 = (params) => {
663
643
  };
664
644
  const isWritable = async (path2) => {
665
645
  try {
666
- await fs__namespace.promises.access(path2, fs__namespace.constants.W_OK);
646
+ await fs.promises.access(path2, fs.constants.W_OK);
667
647
  } catch (error) {
668
648
  log(`${path2} is not writable: %s %s`, error.message, error.stack);
669
649
  return false;
@@ -681,23 +661,23 @@ const create$1 = (params) => {
681
661
  };
682
662
  const createDirectory = async (path2) => {
683
663
  try {
684
- await fs__namespace.promises.mkdir(path2, { recursive: true });
664
+ await fs.promises.mkdir(path2, { recursive: true });
685
665
  } catch (mkdirError) {
686
666
  throw new Error(`Failed to create output directory ${path2}: ${mkdirError.message} ${mkdirError.stack}`);
687
667
  }
688
668
  };
689
669
  const readFile = async (path2, encoding) => {
690
- return await fs__namespace.promises.readFile(path2, { encoding });
670
+ return await fs.promises.readFile(path2, { encoding });
691
671
  };
692
672
  const writeFile = async (path2, data, encoding) => {
693
- await fs__namespace.promises.writeFile(path2, data, { encoding });
673
+ await fs.promises.writeFile(path2, data, { encoding });
694
674
  };
695
675
  const forEachFileIn = async (directory, callback, options = { pattern: "*.*" }) => {
696
676
  try {
697
677
  let filesProcessed = 0;
698
- const files = await glob.glob(options.pattern, { cwd: directory, nodir: true });
678
+ const files = await glob(options.pattern, { cwd: directory, nodir: true });
699
679
  for (const file of files) {
700
- await callback(path.join(directory, file));
680
+ await callback(path__default.join(directory, file));
701
681
  filesProcessed++;
702
682
  if (options.limit && filesProcessed >= options.limit) {
703
683
  log(`Reached limit of ${options.limit} files, stopping`);
@@ -709,14 +689,14 @@ const create$1 = (params) => {
709
689
  }
710
690
  };
711
691
  const readStream = async (path2) => {
712
- return fs__namespace.createReadStream(path2);
692
+ return fs.createReadStream(path2);
713
693
  };
714
694
  const hashFile = async (path2, length) => {
715
695
  const file = await readFile(path2, "utf8");
716
696
  return crypto.createHash("sha256").update(file).digest("hex").slice(0, length);
717
697
  };
718
698
  const listFiles = async (directory) => {
719
- return await fs__namespace.promises.readdir(directory);
699
+ return await fs.promises.readdir(directory);
720
700
  };
721
701
  return {
722
702
  exists,
@@ -736,9 +716,9 @@ const create$1 = (params) => {
736
716
  listFiles
737
717
  };
738
718
  };
739
- const OptionsSchema = zod.z.object({
740
- logger: zod.z.any().optional().default(DEFAULT_LOGGER),
741
- ignorePatterns: zod.z.array(zod.z.string()).optional().default(DEFAULT_IGNORE_PATTERNS),
719
+ const OptionsSchema = z.object({
720
+ logger: z.any().optional().default(DEFAULT_LOGGER),
721
+ ignorePatterns: z.array(z.string()).optional().default(DEFAULT_IGNORE_PATTERNS),
742
722
  parameters: ParametersSchema.optional().default({})
743
723
  });
744
724
  function extractFirstHeader(markdownText) {
@@ -783,10 +763,10 @@ const create = (loaderOptions) => {
783
763
  const storage = create$1({ log: logger.debug });
784
764
  for (const contextDir of contextDirectories) {
785
765
  try {
786
- const dirName = path.basename(contextDir);
766
+ const dirName = path__default.basename(contextDir);
787
767
  logger.debug(`Processing context directory ${dirName}`);
788
768
  let mainContextSection;
789
- const contextFile = path.join(contextDir, "context.md");
769
+ const contextFile = path__default.join(contextDir, "context.md");
790
770
  if (await storage.exists(contextFile)) {
791
771
  logger.debug(`Found context.md file in ${contextDir}`);
792
772
  const mainContextContent = await storage.readFile(contextFile, "utf8");
@@ -811,13 +791,13 @@ const create = (loaderOptions) => {
811
791
  }
812
792
  });
813
793
  const filteredFiles = files.filter((file) => {
814
- const fullPath = path.join(contextDir, file);
794
+ const fullPath = path__default.join(contextDir, file);
815
795
  return !ignorePatternsRegex.some((regex) => regex.test(file) || regex.test(fullPath));
816
796
  });
817
797
  for (const file of filteredFiles) {
818
798
  if (file === "context.md") continue;
819
799
  logger.debug(`Processing file ${file} in ${contextDir}`);
820
- const filePath = path.join(contextDir, file);
800
+ const filePath = path__default.join(contextDir, file);
821
801
  if (await storage.isFile(filePath)) {
822
802
  const fileContent = await storage.readFile(filePath, "utf8");
823
803
  let sectionName = file;
@@ -845,107 +825,107 @@ const create = (loaderOptions) => {
845
825
  load
846
826
  };
847
827
  };
848
- zod.z.object({
849
- logger: zod.z.any().optional().default(DEFAULT_LOGGER),
850
- configDirs: zod.z.array(zod.z.string()).default(["./overrides"]),
851
- overrides: zod.z.boolean().default(false),
828
+ z.object({
829
+ logger: z.any().optional().default(DEFAULT_LOGGER),
830
+ configDirs: z.array(z.string()).default(["./overrides"]),
831
+ overrides: z.boolean().default(false),
852
832
  parameters: ParametersSchema.optional().default({})
853
833
  });
854
- zod.z.object({
855
- logger: zod.z.any().optional().default(DEFAULT_LOGGER),
856
- basePath: zod.z.string(),
857
- overridePaths: zod.z.array(zod.z.string()).optional().default(["./"]),
858
- overrides: zod.z.boolean().optional().default(false),
834
+ z.object({
835
+ logger: z.any().optional().default(DEFAULT_LOGGER),
836
+ basePath: z.string(),
837
+ overridePaths: z.array(z.string()).optional().default(["./"]),
838
+ overrides: z.boolean().optional().default(false),
859
839
  parameters: ParametersSchema.optional().default({})
860
840
  });
861
- zod.z.object({
862
- model: zod.z.string(),
863
- formatter: zod.z.any().optional(),
864
- trackContext: zod.z.boolean().optional().default(true),
865
- deduplicateContext: zod.z.boolean().optional().default(true)
841
+ z.object({
842
+ model: z.string(),
843
+ formatter: z.any().optional(),
844
+ trackContext: z.boolean().optional().default(true),
845
+ deduplicateContext: z.boolean().optional().default(true)
866
846
  });
867
- zod.z.object({
868
- name: zod.z.string().min(1),
869
- description: zod.z.string().min(1),
870
- parameters: zod.z.object({
871
- type: zod.z.literal("object"),
872
- properties: zod.z.record(zod.z.string(), zod.z.any()).default({}),
847
+ z.object({
848
+ name: z.string().min(1),
849
+ description: z.string().min(1),
850
+ parameters: z.object({
851
+ type: z.literal("object"),
852
+ properties: z.record(z.string(), z.any()).default({}),
873
853
  // Allow any parameter structure
874
- required: zod.z.array(zod.z.string()).optional()
854
+ required: z.array(z.string()).optional()
875
855
  }).passthrough(),
876
856
  // Allow additional fields
877
- execute: zod.z.custom(
857
+ execute: z.custom(
878
858
  (val) => typeof val === "function",
879
859
  { message: "execute must be a function" }
880
860
  ),
881
- category: zod.z.string().optional(),
882
- cost: zod.z.enum(["cheap", "moderate", "expensive"]).optional(),
883
- examples: zod.z.array(zod.z.object({
884
- scenario: zod.z.string(),
885
- params: zod.z.any(),
886
- expectedResult: zod.z.string()
861
+ category: z.string().optional(),
862
+ cost: z.enum(["cheap", "moderate", "expensive"]).optional(),
863
+ examples: z.array(z.object({
864
+ scenario: z.string(),
865
+ params: z.any(),
866
+ expectedResult: z.string()
887
867
  })).optional()
888
868
  }).passthrough();
889
- const ContentItemSchema = zod.z.union([
890
- zod.z.string(),
869
+ const ContentItemSchema = z.union([
870
+ z.string(),
891
871
  // Simple string content
892
- zod.z.object({
893
- content: zod.z.string(),
894
- title: zod.z.string().optional(),
895
- weight: zod.z.number().optional()
872
+ z.object({
873
+ content: z.string(),
874
+ title: z.string().optional(),
875
+ weight: z.number().optional()
896
876
  }),
897
- zod.z.object({
898
- path: zod.z.string(),
899
- title: zod.z.string().optional(),
900
- weight: zod.z.number().optional()
877
+ z.object({
878
+ path: z.string(),
879
+ title: z.string().optional(),
880
+ weight: z.number().optional()
901
881
  }),
902
- zod.z.object({
903
- directories: zod.z.array(zod.z.string()),
904
- title: zod.z.string().optional(),
905
- weight: zod.z.number().optional()
882
+ z.object({
883
+ directories: z.array(z.string()),
884
+ title: z.string().optional(),
885
+ weight: z.number().optional()
906
886
  })
907
887
  ]);
908
- zod.z.object({
888
+ z.object({
909
889
  // Core settings
910
- basePath: zod.z.string(),
911
- logger: zod.z.any().optional().default(DEFAULT_LOGGER),
912
- overridePaths: zod.z.array(zod.z.string()).optional().default(["./"]),
913
- overrides: zod.z.boolean().optional().default(false),
890
+ basePath: z.string(),
891
+ logger: z.any().optional().default(DEFAULT_LOGGER),
892
+ overridePaths: z.array(z.string()).optional().default(["./"]),
893
+ overrides: z.boolean().optional().default(false),
914
894
  parameters: ParametersSchema.optional().default({}),
915
895
  // Content sections
916
896
  persona: ContentItemSchema.optional(),
917
- instructions: zod.z.array(ContentItemSchema).optional().default([]),
918
- content: zod.z.array(ContentItemSchema).optional().default([]),
919
- context: zod.z.array(ContentItemSchema).optional().default([]),
897
+ instructions: z.array(ContentItemSchema).optional().default([]),
898
+ content: z.array(ContentItemSchema).optional().default([]),
899
+ context: z.array(ContentItemSchema).optional().default([]),
920
900
  // Advanced prompting sections
921
- constraints: zod.z.array(ContentItemSchema).optional().default([]),
922
- tone: zod.z.array(ContentItemSchema).optional().default([]),
923
- examples: zod.z.array(ContentItemSchema).optional().default([]),
924
- reasoning: zod.z.array(ContentItemSchema).optional().default([]),
925
- responseFormat: zod.z.array(ContentItemSchema).optional().default([]),
926
- recap: zod.z.array(ContentItemSchema).optional().default([]),
927
- safeguards: zod.z.array(ContentItemSchema).optional().default([]),
928
- schema: zod.z.any().optional(),
901
+ constraints: z.array(ContentItemSchema).optional().default([]),
902
+ tone: z.array(ContentItemSchema).optional().default([]),
903
+ examples: z.array(ContentItemSchema).optional().default([]),
904
+ reasoning: z.array(ContentItemSchema).optional().default([]),
905
+ responseFormat: z.array(ContentItemSchema).optional().default([]),
906
+ recap: z.array(ContentItemSchema).optional().default([]),
907
+ safeguards: z.array(ContentItemSchema).optional().default([]),
908
+ schema: z.any().optional(),
929
909
  // Can be string path, JSON object, or Zod schema
930
910
  // Templates and inheritance
931
- extends: zod.z.string().optional(),
911
+ extends: z.string().optional(),
932
912
  // Extend another recipe
933
- template: zod.z.string().optional(),
913
+ template: z.string().optional(),
934
914
  // Generic template name
935
915
  // Tool integration
936
- tools: zod.z.any().optional(),
916
+ tools: z.any().optional(),
937
917
  // Tool[] | ToolRegistry
938
- toolGuidance: zod.z.union([
939
- zod.z.enum(["auto", "minimal", "detailed"]),
940
- zod.z.object({
941
- strategy: zod.z.enum(["adaptive", "prescriptive", "minimal"]),
942
- includeExamples: zod.z.boolean().optional(),
943
- explainWhenToUse: zod.z.boolean().optional(),
944
- includeCategories: zod.z.boolean().optional(),
945
- customInstructions: zod.z.string().optional()
918
+ toolGuidance: z.union([
919
+ z.enum(["auto", "minimal", "detailed"]),
920
+ z.object({
921
+ strategy: z.enum(["adaptive", "prescriptive", "minimal"]),
922
+ includeExamples: z.boolean().optional(),
923
+ explainWhenToUse: z.boolean().optional(),
924
+ includeCategories: z.boolean().optional(),
925
+ customInstructions: z.string().optional()
946
926
  })
947
927
  ]).optional(),
948
- toolCategories: zod.z.array(zod.z.string()).optional()
928
+ toolCategories: z.array(z.string()).optional()
949
929
  });
950
930
  const toJSON = (prompt) => {
951
931
  return JSON.stringify(prompt, null, 2);
@@ -1087,7 +1067,7 @@ const parseNodeToSection = (node) => {
1087
1067
  return section;
1088
1068
  };
1089
1069
  const fromXML = (xmlString) => {
1090
- const parser = new fastXmlParser.XMLParser({
1070
+ const parser = new XMLParser({
1091
1071
  ignoreAttributes: false,
1092
1072
  attributeNamePrefix: "@_",
1093
1073
  preserveOrder: true,
@@ -1129,18 +1109,18 @@ const fromXML = (xmlString) => {
1129
1109
  });
1130
1110
  };
1131
1111
  const saveToDirectory = async (prompt, basePath) => {
1132
- await fs__namespace$1.mkdir(basePath, { recursive: true });
1112
+ await fs$1.mkdir(basePath, { recursive: true });
1133
1113
  if (prompt.persona) {
1134
- await saveSection(prompt.persona, path__namespace.join(basePath, "persona"));
1114
+ await saveSection(prompt.persona, path.join(basePath, "persona"));
1135
1115
  }
1136
1116
  if (prompt.instructions) {
1137
- await saveSection(prompt.instructions, path__namespace.join(basePath, "instructions"));
1117
+ await saveSection(prompt.instructions, path.join(basePath, "instructions"));
1138
1118
  }
1139
1119
  if (prompt.contexts) {
1140
- await saveSection(prompt.contexts, path__namespace.join(basePath, "context"));
1120
+ await saveSection(prompt.contexts, path.join(basePath, "context"));
1141
1121
  }
1142
1122
  if (prompt.contents) {
1143
- await saveSection(prompt.contents, path__namespace.join(basePath, "content"));
1123
+ await saveSection(prompt.contents, path.join(basePath, "content"));
1144
1124
  }
1145
1125
  };
1146
1126
  const saveSection = async (section, targetPath) => {
@@ -1152,20 +1132,20 @@ const saveSection = async (section, targetPath) => {
1152
1132
  if (typeof item === "string") return item;
1153
1133
  return item.text;
1154
1134
  }).join("\n\n");
1155
- await fs__namespace$1.writeFile(`${targetPath}.md`, content);
1135
+ await fs$1.writeFile(`${targetPath}.md`, content);
1156
1136
  return;
1157
1137
  }
1158
- await fs__namespace$1.mkdir(targetPath, { recursive: true });
1138
+ await fs$1.mkdir(targetPath, { recursive: true });
1159
1139
  for (let i = 0; i < section.items.length; i++) {
1160
1140
  const item = section.items[i];
1161
1141
  if (typeof item === "object" && "items" in item) {
1162
1142
  const subTitle = item.title || `part-${i + 1}`;
1163
- const subPath = path__namespace.join(targetPath, subTitle);
1143
+ const subPath = path.join(targetPath, subTitle);
1164
1144
  await saveSection(item, subPath);
1165
1145
  } else {
1166
1146
  const fileName = `item-${i + 1}.md`;
1167
1147
  const content = typeof item === "string" ? item : item.text;
1168
- await fs__namespace$1.writeFile(path__namespace.join(targetPath, fileName), content);
1148
+ await fs$1.writeFile(path.join(targetPath, fileName), content);
1169
1149
  }
1170
1150
  }
1171
1151
  };
@@ -1258,7 +1238,7 @@ class GeminiProvider {
1258
1238
  async execute(request, options = {}) {
1259
1239
  const apiKey = options.apiKey || process.env.GEMINI_API_KEY;
1260
1240
  if (!apiKey) throw new Error("Gemini API key is required");
1261
- const genAI = new generativeAi.GoogleGenerativeAI(apiKey);
1241
+ const genAI = new GoogleGenerativeAI(apiKey);
1262
1242
  const modelName = options.model || request.model || "gemini-1.5-pro";
1263
1243
  const generationConfig = {};
1264
1244
  if (request.responseFormat?.type === "json_schema") {
@@ -1364,8 +1344,8 @@ const execute = async (request, options = {}) => {
1364
1344
  const manager = new ExecutionManager();
1365
1345
  return manager.execute(request, options);
1366
1346
  };
1367
- const program = new commander.Command();
1368
- const configManager = cardigantime.create({
1347
+ const program = new Command();
1348
+ const configManager = create$7({
1369
1349
  configShape: ConfigSchema.shape,
1370
1350
  defaults: {
1371
1351
  configDirectory: process.cwd(),
@@ -1375,7 +1355,7 @@ const configManager = cardigantime.create({
1375
1355
  program.name("riotprompt").description("CLI tool for analyzing and processing prompts").version("0.0.1");
1376
1356
  async function isDirectory(path2) {
1377
1357
  try {
1378
- const stat = await fs__namespace$1.stat(path2);
1358
+ const stat = await fs$1.stat(path2);
1379
1359
  return stat.isDirectory();
1380
1360
  } catch {
1381
1361
  return false;
@@ -1383,7 +1363,7 @@ async function isDirectory(path2) {
1383
1363
  }
1384
1364
  async function fileExists(path2) {
1385
1365
  try {
1386
- await fs__namespace$1.access(path2);
1366
+ await fs$1.access(path2);
1387
1367
  return true;
1388
1368
  } catch {
1389
1369
  return false;
@@ -1394,8 +1374,8 @@ async function loadPromptFromDirectory(absolutePromptPath) {
1394
1374
  let instructionsSection;
1395
1375
  let contextSection;
1396
1376
  const loader = create();
1397
- const personaDir = path__namespace.join(absolutePromptPath, "persona");
1398
- const personaFile = path__namespace.join(absolutePromptPath, "persona.md");
1377
+ const personaDir = path.join(absolutePromptPath, "persona");
1378
+ const personaFile = path.join(absolutePromptPath, "persona.md");
1399
1379
  if (await isDirectory(personaDir)) {
1400
1380
  console.log("Loading persona from directory...");
1401
1381
  const personaSections = await loader.load([personaDir]);
@@ -1407,14 +1387,14 @@ async function loadPromptFromDirectory(absolutePromptPath) {
1407
1387
  }
1408
1388
  } else if (await fileExists(personaFile)) {
1409
1389
  console.log("Loading persona from file...");
1410
- const personaContent = await fs__namespace$1.readFile(personaFile, "utf-8");
1390
+ const personaContent = await fs$1.readFile(personaFile, "utf-8");
1411
1391
  personaSection = create$4({ title: "Persona" });
1412
1392
  personaSection.add(create$5(personaContent));
1413
1393
  } else {
1414
1394
  console.log("No persona found, skipping.");
1415
1395
  }
1416
- const instructionsDir = path__namespace.join(absolutePromptPath, "instructions");
1417
- const instructionsFile = path__namespace.join(absolutePromptPath, "instructions.md");
1396
+ const instructionsDir = path.join(absolutePromptPath, "instructions");
1397
+ const instructionsFile = path.join(absolutePromptPath, "instructions.md");
1418
1398
  if (await isDirectory(instructionsDir)) {
1419
1399
  console.log("Loading instructions from directory...");
1420
1400
  const instructionSections = await loader.load([instructionsDir]);
@@ -1426,14 +1406,14 @@ async function loadPromptFromDirectory(absolutePromptPath) {
1426
1406
  }
1427
1407
  } else if (await fileExists(instructionsFile)) {
1428
1408
  console.log("Loading instructions from file...");
1429
- const instructionsContent = await fs__namespace$1.readFile(instructionsFile, "utf-8");
1409
+ const instructionsContent = await fs$1.readFile(instructionsFile, "utf-8");
1430
1410
  instructionsSection = create$4({ title: "Instructions" });
1431
1411
  instructionsSection.add(create$5(instructionsContent));
1432
1412
  }
1433
1413
  if (!instructionsSection) {
1434
1414
  throw new Error("instructions (directory or .md file) is required.");
1435
1415
  }
1436
- const contextDir = path__namespace.join(absolutePromptPath, "context");
1416
+ const contextDir = path.join(absolutePromptPath, "context");
1437
1417
  if (await isDirectory(contextDir)) {
1438
1418
  console.log("Loading context from directory...");
1439
1419
  const contextSections = await loader.load([contextDir]);
@@ -1454,14 +1434,14 @@ async function loadPromptFromDirectory(absolutePromptPath) {
1454
1434
  }
1455
1435
  async function createAction(promptName, options) {
1456
1436
  try {
1457
- const basePath = path__namespace.resolve(options.path, promptName);
1437
+ const basePath = path.resolve(options.path, promptName);
1458
1438
  if (await fileExists(basePath)) {
1459
1439
  console.error(`Error: Directory ${basePath} already exists.`);
1460
1440
  process.exit(1);
1461
1441
  }
1462
1442
  if (options.import) {
1463
1443
  console.log(`Importing prompt from ${options.import} to ${basePath}...`);
1464
- const content = await fs__namespace$1.readFile(options.import, "utf-8");
1444
+ const content = await fs$1.readFile(options.import, "utf-8");
1465
1445
  let prompt;
1466
1446
  if (options.import.endsWith(".json")) {
1467
1447
  prompt = fromJSON(content);
@@ -1474,23 +1454,23 @@ async function createAction(promptName, options) {
1474
1454
  console.log(`Successfully imported to ${basePath}`);
1475
1455
  } else {
1476
1456
  console.log(`Creating prompt structure at ${basePath}...`);
1477
- await fs__namespace$1.mkdir(basePath, { recursive: true });
1457
+ await fs$1.mkdir(basePath, { recursive: true });
1478
1458
  const personaText = options.persona || "You are a helpful AI assistant.";
1479
- await fs__namespace$1.writeFile(path__namespace.join(basePath, "persona.md"), personaText);
1459
+ await fs$1.writeFile(path.join(basePath, "persona.md"), personaText);
1480
1460
  console.log("Created persona.md");
1481
1461
  const instructionsText = options.instructions || "Please analyze the following request.";
1482
- await fs__namespace$1.writeFile(path__namespace.join(basePath, "instructions.md"), instructionsText);
1462
+ await fs$1.writeFile(path.join(basePath, "instructions.md"), instructionsText);
1483
1463
  console.log("Created instructions.md");
1484
1464
  if (options.context) {
1485
- const contextDir = path__namespace.join(basePath, "context");
1486
- await fs__namespace$1.mkdir(contextDir);
1487
- await fs__namespace$1.writeFile(path__namespace.join(contextDir, "README.md"), "Place context files (json, md, txt) in this directory.");
1465
+ const contextDir = path.join(basePath, "context");
1466
+ await fs$1.mkdir(contextDir);
1467
+ await fs$1.writeFile(path.join(contextDir, "README.md"), "Place context files (json, md, txt) in this directory.");
1488
1468
  console.log("Created context directory");
1489
1469
  }
1490
1470
  console.log(`
1491
1471
  Prompt '${promptName}' created successfully!`);
1492
1472
  }
1493
- console.log(`Run 'riotprompt process ${path__namespace.join(options.path, promptName)}' to test it.`);
1473
+ console.log(`Run 'riotprompt process ${path.join(options.path, promptName)}' to test it.`);
1494
1474
  } catch (error) {
1495
1475
  console.error("Error creating prompt:", error);
1496
1476
  process.exit(1);
@@ -1502,7 +1482,7 @@ async function processAction(promptPath, options) {
1502
1482
  const modelName = options.model || config.defaultModel;
1503
1483
  console.log(`Processing prompt from: ${promptPath}`);
1504
1484
  console.log(`Using model: ${modelName}`);
1505
- const absolutePromptPath = path__namespace.resolve(promptPath);
1485
+ const absolutePromptPath = path.resolve(promptPath);
1506
1486
  if (!await fileExists(absolutePromptPath)) {
1507
1487
  console.error(`Error: Prompt path not found at ${absolutePromptPath}`);
1508
1488
  process.exit(1);
@@ -1511,7 +1491,7 @@ async function processAction(promptPath, options) {
1511
1491
  if (await isDirectory(absolutePromptPath)) {
1512
1492
  prompt = await loadPromptFromDirectory(absolutePromptPath);
1513
1493
  } else {
1514
- const content = await fs__namespace$1.readFile(absolutePromptPath, "utf-8");
1494
+ const content = await fs$1.readFile(absolutePromptPath, "utf-8");
1515
1495
  if (absolutePromptPath.endsWith(".json")) {
1516
1496
  prompt = fromJSON(content);
1517
1497
  } else if (absolutePromptPath.endsWith(".xml")) {
@@ -1538,7 +1518,7 @@ ${m.content}`).join("\n\n");
1538
1518
  }
1539
1519
  }
1540
1520
  if (options.output) {
1541
- await fs__namespace$1.writeFile(options.output, output);
1521
+ await fs$1.writeFile(options.output, output);
1542
1522
  console.log(`Output written to ${options.output}`);
1543
1523
  } else {
1544
1524
  console.log("\n--- Result ---\n");
@@ -1555,7 +1535,7 @@ async function executeAction(promptPath, options) {
1555
1535
  const modelName = options.model || config.defaultModel;
1556
1536
  console.log(`Executing prompt from: ${promptPath}`);
1557
1537
  console.log(`Using model: ${modelName}`);
1558
- const absolutePromptPath = path__namespace.resolve(promptPath);
1538
+ const absolutePromptPath = path.resolve(promptPath);
1559
1539
  if (!await fileExists(absolutePromptPath)) {
1560
1540
  console.error(`Error: Prompt path not found at ${absolutePromptPath}`);
1561
1541
  process.exit(1);
@@ -1564,7 +1544,7 @@ async function executeAction(promptPath, options) {
1564
1544
  if (await isDirectory(absolutePromptPath)) {
1565
1545
  prompt = await loadPromptFromDirectory(absolutePromptPath);
1566
1546
  } else {
1567
- const content = await fs__namespace$1.readFile(absolutePromptPath, "utf-8");
1547
+ const content = await fs$1.readFile(absolutePromptPath, "utf-8");
1568
1548
  if (absolutePromptPath.endsWith(".json")) {
1569
1549
  prompt = fromJSON(content);
1570
1550
  } else if (absolutePromptPath.endsWith(".xml")) {
@@ -1602,16 +1582,19 @@ async function main() {
1602
1582
  program.command("execute <promptPath>").description("Execute a prompt using an LLM provider").option("-m, --model <model>", "Model to use (e.g., gpt-4, claude-3-opus, gemini-1.5-pro)").option("-k, --key <key>", "API Key (overrides env vars)").option("-t, --temperature <number>", "Temperature (0-1)", parseFloat).option("--max-tokens <number>", "Max tokens", parseInt).action(executeAction);
1603
1583
  await program.parseAsync();
1604
1584
  }
1605
- if (typeof require !== "undefined" && require.main === module) {
1585
+ const isRunningAsCLI = process.argv[1] && (process.argv[1].endsWith("cli.js") || process.argv[1].endsWith("cli.ts")) && !process.argv[1].includes("vitest") && !process.argv[1].includes("node_modules");
1586
+ if (isRunningAsCLI) {
1606
1587
  main().catch((err) => {
1607
1588
  console.error(err);
1608
1589
  process.exit(1);
1609
1590
  });
1610
1591
  }
1611
- exports.createAction = createAction;
1612
- exports.executeAction = executeAction;
1613
- exports.fileExists = fileExists;
1614
- exports.isDirectory = isDirectory;
1615
- exports.loadPromptFromDirectory = loadPromptFromDirectory;
1616
- exports.main = main;
1617
- exports.processAction = processAction;
1592
+ export {
1593
+ createAction,
1594
+ executeAction,
1595
+ fileExists,
1596
+ isDirectory,
1597
+ loadPromptFromDirectory,
1598
+ main,
1599
+ processAction
1600
+ };