@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.
- package/dist/{cli.cjs → cli.js} +177 -194
- package/dist/util/storage.js.map +1 -1
- package/package.json +12 -12
- package/vite.config.cli.ts +9 -18
- package/dist/riotprompt.cjs +0 -6169
- package/dist/riotprompt.cjs.map +0 -1
package/dist/{cli.cjs → cli.js}
RENAMED
|
@@ -1,46 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 =
|
|
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
|
-
|
|
71
|
-
text:
|
|
72
|
-
weight:
|
|
50
|
+
z.object({
|
|
51
|
+
text: z.string(),
|
|
52
|
+
weight: z.number().optional()
|
|
73
53
|
});
|
|
74
|
-
const WeightedOptionsSchema =
|
|
75
|
-
weight:
|
|
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 =
|
|
91
|
-
title:
|
|
92
|
-
weight:
|
|
93
|
-
itemWeight:
|
|
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 =
|
|
490
|
-
const SectionTitlePropertySchema =
|
|
491
|
-
const FormatOptionsSchema =
|
|
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:
|
|
473
|
+
sectionIndentation: z.boolean(),
|
|
494
474
|
sectionTitleProperty: SectionTitlePropertySchema,
|
|
495
|
-
sectionTitlePrefix:
|
|
496
|
-
sectionTitleSeparator:
|
|
497
|
-
sectionDepth:
|
|
475
|
+
sectionTitlePrefix: z.string().optional(),
|
|
476
|
+
sectionTitleSeparator: z.string().optional(),
|
|
477
|
+
sectionDepth: z.number().default(0)
|
|
498
478
|
});
|
|
499
|
-
const OptionSchema =
|
|
500
|
-
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
|
-
|
|
626
|
-
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
670
|
+
return await fs.promises.readFile(path2, { encoding });
|
|
691
671
|
};
|
|
692
672
|
const writeFile = async (path2, data, encoding) => {
|
|
693
|
-
await
|
|
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
|
|
678
|
+
const files = await glob(options.pattern, { cwd: directory, nodir: true });
|
|
699
679
|
for (const file of files) {
|
|
700
|
-
await callback(
|
|
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
|
|
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
|
|
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 =
|
|
740
|
-
logger:
|
|
741
|
-
ignorePatterns:
|
|
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 =
|
|
766
|
+
const dirName = path__default.basename(contextDir);
|
|
787
767
|
logger.debug(`Processing context directory ${dirName}`);
|
|
788
768
|
let mainContextSection;
|
|
789
|
-
const contextFile =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
849
|
-
logger:
|
|
850
|
-
configDirs:
|
|
851
|
-
overrides:
|
|
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
|
-
|
|
855
|
-
logger:
|
|
856
|
-
basePath:
|
|
857
|
-
overridePaths:
|
|
858
|
-
overrides:
|
|
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
|
-
|
|
862
|
-
model:
|
|
863
|
-
formatter:
|
|
864
|
-
trackContext:
|
|
865
|
-
deduplicateContext:
|
|
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
|
-
|
|
868
|
-
name:
|
|
869
|
-
description:
|
|
870
|
-
parameters:
|
|
871
|
-
type:
|
|
872
|
-
properties:
|
|
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:
|
|
854
|
+
required: z.array(z.string()).optional()
|
|
875
855
|
}).passthrough(),
|
|
876
856
|
// Allow additional fields
|
|
877
|
-
execute:
|
|
857
|
+
execute: z.custom(
|
|
878
858
|
(val) => typeof val === "function",
|
|
879
859
|
{ message: "execute must be a function" }
|
|
880
860
|
),
|
|
881
|
-
category:
|
|
882
|
-
cost:
|
|
883
|
-
examples:
|
|
884
|
-
scenario:
|
|
885
|
-
params:
|
|
886
|
-
expectedResult:
|
|
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 =
|
|
890
|
-
|
|
869
|
+
const ContentItemSchema = z.union([
|
|
870
|
+
z.string(),
|
|
891
871
|
// Simple string content
|
|
892
|
-
|
|
893
|
-
content:
|
|
894
|
-
title:
|
|
895
|
-
weight:
|
|
872
|
+
z.object({
|
|
873
|
+
content: z.string(),
|
|
874
|
+
title: z.string().optional(),
|
|
875
|
+
weight: z.number().optional()
|
|
896
876
|
}),
|
|
897
|
-
|
|
898
|
-
path:
|
|
899
|
-
title:
|
|
900
|
-
weight:
|
|
877
|
+
z.object({
|
|
878
|
+
path: z.string(),
|
|
879
|
+
title: z.string().optional(),
|
|
880
|
+
weight: z.number().optional()
|
|
901
881
|
}),
|
|
902
|
-
|
|
903
|
-
directories:
|
|
904
|
-
title:
|
|
905
|
-
weight:
|
|
882
|
+
z.object({
|
|
883
|
+
directories: z.array(z.string()),
|
|
884
|
+
title: z.string().optional(),
|
|
885
|
+
weight: z.number().optional()
|
|
906
886
|
})
|
|
907
887
|
]);
|
|
908
|
-
|
|
888
|
+
z.object({
|
|
909
889
|
// Core settings
|
|
910
|
-
basePath:
|
|
911
|
-
logger:
|
|
912
|
-
overridePaths:
|
|
913
|
-
overrides:
|
|
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:
|
|
918
|
-
content:
|
|
919
|
-
context:
|
|
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:
|
|
922
|
-
tone:
|
|
923
|
-
examples:
|
|
924
|
-
reasoning:
|
|
925
|
-
responseFormat:
|
|
926
|
-
recap:
|
|
927
|
-
safeguards:
|
|
928
|
-
schema:
|
|
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:
|
|
911
|
+
extends: z.string().optional(),
|
|
932
912
|
// Extend another recipe
|
|
933
|
-
template:
|
|
913
|
+
template: z.string().optional(),
|
|
934
914
|
// Generic template name
|
|
935
915
|
// Tool integration
|
|
936
|
-
tools:
|
|
916
|
+
tools: z.any().optional(),
|
|
937
917
|
// Tool[] | ToolRegistry
|
|
938
|
-
toolGuidance:
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
strategy:
|
|
942
|
-
includeExamples:
|
|
943
|
-
explainWhenToUse:
|
|
944
|
-
includeCategories:
|
|
945
|
-
customInstructions:
|
|
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:
|
|
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
|
|
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
|
|
1112
|
+
await fs$1.mkdir(basePath, { recursive: true });
|
|
1133
1113
|
if (prompt.persona) {
|
|
1134
|
-
await saveSection(prompt.persona,
|
|
1114
|
+
await saveSection(prompt.persona, path.join(basePath, "persona"));
|
|
1135
1115
|
}
|
|
1136
1116
|
if (prompt.instructions) {
|
|
1137
|
-
await saveSection(prompt.instructions,
|
|
1117
|
+
await saveSection(prompt.instructions, path.join(basePath, "instructions"));
|
|
1138
1118
|
}
|
|
1139
1119
|
if (prompt.contexts) {
|
|
1140
|
-
await saveSection(prompt.contexts,
|
|
1120
|
+
await saveSection(prompt.contexts, path.join(basePath, "context"));
|
|
1141
1121
|
}
|
|
1142
1122
|
if (prompt.contents) {
|
|
1143
|
-
await saveSection(prompt.contents,
|
|
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
|
|
1135
|
+
await fs$1.writeFile(`${targetPath}.md`, content);
|
|
1156
1136
|
return;
|
|
1157
1137
|
}
|
|
1158
|
-
await
|
|
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 =
|
|
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
|
|
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
|
|
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
|
|
1368
|
-
const configManager =
|
|
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
|
|
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
|
|
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 =
|
|
1398
|
-
const personaFile =
|
|
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
|
|
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 =
|
|
1417
|
-
const instructionsFile =
|
|
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
|
|
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 =
|
|
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 =
|
|
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
|
|
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
|
|
1457
|
+
await fs$1.mkdir(basePath, { recursive: true });
|
|
1478
1458
|
const personaText = options.persona || "You are a helpful AI assistant.";
|
|
1479
|
-
await
|
|
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
|
|
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 =
|
|
1486
|
-
await
|
|
1487
|
-
await
|
|
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 ${
|
|
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 =
|
|
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
|
|
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
|
|
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 =
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1592
|
+
export {
|
|
1593
|
+
createAction,
|
|
1594
|
+
executeAction,
|
|
1595
|
+
fileExists,
|
|
1596
|
+
isDirectory,
|
|
1597
|
+
loadPromptFromDirectory,
|
|
1598
|
+
main,
|
|
1599
|
+
processAction
|
|
1600
|
+
};
|