@riotprompt/riotprompt 0.0.1 → 0.0.3
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/README.md +54 -470
- package/dist/builder.d.ts +3 -3
- package/dist/builder.js +7 -2
- package/dist/builder.js.map +1 -1
- package/dist/chat.js.map +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/formatter.js.map +1 -1
- package/dist/items/content.js.map +1 -1
- package/dist/items/context.js.map +1 -1
- package/dist/items/instruction.js.map +1 -1
- package/dist/items/parameters.js.map +1 -1
- package/dist/items/section.js.map +1 -1
- package/dist/items/trait.js.map +1 -1
- package/dist/items/weighted.js.map +1 -1
- package/dist/loader.js +1 -0
- package/dist/loader.js.map +1 -1
- package/dist/logger.js +4 -2
- package/dist/logger.js.map +1 -1
- package/dist/override.d.ts +5 -5
- package/dist/override.js +47 -30
- package/dist/override.js.map +1 -1
- package/dist/parse/markdown.js.map +1 -1
- package/dist/parse/text.js.map +1 -1
- package/dist/parser.js.map +1 -1
- package/dist/prompt.js.map +1 -1
- package/dist/recipes.d.ts +405 -0
- package/dist/recipes.js +424 -0
- package/dist/recipes.js.map +1 -0
- package/dist/riotprompt.cjs +586 -132
- package/dist/riotprompt.cjs.map +1 -1
- package/dist/riotprompt.d.ts +3 -0
- package/dist/riotprompt.js +3 -0
- package/dist/riotprompt.js.map +1 -1
- package/dist/util/general.js.map +1 -1
- package/dist/util/markdown.js.map +1 -1
- package/dist/util/storage.js.map +1 -1
- package/dist/util/text.js.map +1 -1
- package/package.json +35 -28
- package/.gitcarve/config.yaml +0 -10
- package/.gitcarve/context/content.md +0 -11
- package/.markdown-doctest-setup.mjs +0 -23
- package/.nvmrc +0 -1
- package/dist/builder.cjs +0 -152
- package/dist/builder.cjs.map +0 -1
- package/dist/chat.cjs +0 -26
- package/dist/chat.cjs.map +0 -1
- package/dist/constants.cjs +0 -34
- package/dist/constants.cjs.map +0 -1
- package/dist/formatter.cjs +0 -139
- package/dist/formatter.cjs.map +0 -1
- package/dist/items/content.cjs +0 -14
- package/dist/items/content.cjs.map +0 -1
- package/dist/items/context.cjs +0 -13
- package/dist/items/context.cjs.map +0 -1
- package/dist/items/instruction.cjs +0 -13
- package/dist/items/instruction.cjs.map +0 -1
- package/dist/items/parameters.cjs +0 -53
- package/dist/items/parameters.cjs.map +0 -1
- package/dist/items/section.cjs +0 -120
- package/dist/items/section.cjs.map +0 -1
- package/dist/items/trait.cjs +0 -13
- package/dist/items/trait.cjs.map +0 -1
- package/dist/items/weighted.cjs +0 -27
- package/dist/items/weighted.cjs.map +0 -1
- package/dist/loader.cjs +0 -167
- package/dist/loader.cjs.map +0 -1
- package/dist/logger.cjs +0 -51
- package/dist/logger.cjs.map +0 -1
- package/dist/override.cjs +0 -109
- package/dist/override.cjs.map +0 -1
- package/dist/parse/markdown.cjs +0 -114
- package/dist/parse/markdown.cjs.map +0 -1
- package/dist/parse/text.cjs +0 -33
- package/dist/parse/text.cjs.map +0 -1
- package/dist/parser.cjs +0 -99
- package/dist/parser.cjs.map +0 -1
- package/dist/prompt.cjs +0 -15
- package/dist/prompt.cjs.map +0 -1
- package/dist/util/general.cjs +0 -52
- package/dist/util/general.cjs.map +0 -1
- package/dist/util/markdown.cjs +0 -115
- package/dist/util/markdown.cjs.map +0 -1
- package/dist/util/storage.cjs +0 -155
- package/dist/util/storage.cjs.map +0 -1
- package/dist/util/text.cjs +0 -42
- package/dist/util/text.cjs.map +0 -1
- package/docs/loader.md +0 -237
- package/docs/override.md +0 -323
- package/docs/parser.md +0 -130
- package/eslint.config.mjs +0 -82
- package/nodemon.json +0 -14
- package/vite.config.ts +0 -114
- package/vitest.config.ts +0 -25
package/dist/riotprompt.cjs
CHANGED
|
@@ -31,7 +31,7 @@ const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
|
31
31
|
const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
32
32
|
const fs__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(fs$1);
|
|
33
33
|
|
|
34
|
-
const
|
|
34
|
+
const ParametersSchema = zod.z.record(zod.z.string(), zod.z.union([
|
|
35
35
|
zod.z.string(),
|
|
36
36
|
zod.z.number(),
|
|
37
37
|
zod.z.boolean(),
|
|
@@ -41,7 +41,7 @@ const parameters.ParametersSchema = zod.z.record(zod.z.string(), zod.z.union([
|
|
|
41
41
|
zod.z.boolean()
|
|
42
42
|
]))
|
|
43
43
|
]));
|
|
44
|
-
const create$
|
|
44
|
+
const create$d = (parameters)=>{
|
|
45
45
|
return parameters;
|
|
46
46
|
};
|
|
47
47
|
const apply = (text, parameters)=>{
|
|
@@ -78,12 +78,12 @@ zod.z.object({
|
|
|
78
78
|
text: zod.z.string(),
|
|
79
79
|
weight: zod.z.number().optional()
|
|
80
80
|
});
|
|
81
|
-
const
|
|
81
|
+
const WeightedOptionsSchema = zod.z.object({
|
|
82
82
|
weight: zod.z.number().optional(),
|
|
83
|
-
parameters:
|
|
83
|
+
parameters: ParametersSchema.optional()
|
|
84
84
|
});
|
|
85
|
-
const create$
|
|
86
|
-
const weightedOptions =
|
|
85
|
+
const create$c = (text, options = {})=>{
|
|
86
|
+
const weightedOptions = WeightedOptionsSchema.parse(options);
|
|
87
87
|
const parameterizedText = apply(text, weightedOptions.parameters);
|
|
88
88
|
return {
|
|
89
89
|
text: parameterizedText,
|
|
@@ -92,36 +92,36 @@ const create$8 = (text, options = {})=>{
|
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
// Export create function
|
|
95
|
-
const create$
|
|
96
|
-
const weightedOptions =
|
|
97
|
-
return create$
|
|
95
|
+
const create$b = (text, options = {})=>{
|
|
96
|
+
const weightedOptions = WeightedOptionsSchema.parse(options);
|
|
97
|
+
return create$c(text, weightedOptions);
|
|
98
98
|
};
|
|
99
99
|
|
|
100
|
-
const create$
|
|
101
|
-
const weightedOptions =
|
|
102
|
-
return create$
|
|
100
|
+
const create$a = (text, options = {})=>{
|
|
101
|
+
const weightedOptions = WeightedOptionsSchema.parse(options);
|
|
102
|
+
return create$c(text, weightedOptions);
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
const create$
|
|
106
|
-
const weightedOptions =
|
|
107
|
-
return create$
|
|
105
|
+
const create$9 = (text, options = {})=>{
|
|
106
|
+
const weightedOptions = WeightedOptionsSchema.parse(options);
|
|
107
|
+
return create$c(text, weightedOptions);
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
const
|
|
110
|
+
const SectionOptionsSchema = zod.z.object({
|
|
111
111
|
title: zod.z.string().optional(),
|
|
112
112
|
weight: zod.z.number().optional(),
|
|
113
113
|
itemWeight: zod.z.number().optional(),
|
|
114
|
-
parameters:
|
|
114
|
+
parameters: ParametersSchema.optional().default({})
|
|
115
115
|
});
|
|
116
|
-
const create$
|
|
116
|
+
const create$8 = (options = {})=>{
|
|
117
117
|
const items = [];
|
|
118
|
-
const sectionOptions =
|
|
119
|
-
const sectionItemOptions =
|
|
118
|
+
const sectionOptions = SectionOptionsSchema.parse(options);
|
|
119
|
+
const sectionItemOptions = WeightedOptionsSchema.parse({
|
|
120
120
|
...sectionOptions,
|
|
121
121
|
weight: sectionOptions.itemWeight
|
|
122
122
|
});
|
|
123
123
|
const append = (item, options = {})=>{
|
|
124
|
-
let itemOptions =
|
|
124
|
+
let itemOptions = WeightedOptionsSchema.parse(options);
|
|
125
125
|
itemOptions = {
|
|
126
126
|
...sectionItemOptions,
|
|
127
127
|
...itemOptions
|
|
@@ -132,15 +132,15 @@ const create$4 = (options = {})=>{
|
|
|
132
132
|
});
|
|
133
133
|
} else {
|
|
134
134
|
if (typeof item === 'string') {
|
|
135
|
-
items.push(create$
|
|
135
|
+
items.push(create$c(item, itemOptions));
|
|
136
136
|
} else {
|
|
137
137
|
items.push(item);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
return section
|
|
140
|
+
return section;
|
|
141
141
|
};
|
|
142
142
|
const prepend = (item, options = {})=>{
|
|
143
|
-
let itemOptions =
|
|
143
|
+
let itemOptions = WeightedOptionsSchema.parse(options);
|
|
144
144
|
itemOptions = {
|
|
145
145
|
...sectionItemOptions,
|
|
146
146
|
...itemOptions
|
|
@@ -151,15 +151,15 @@ const create$4 = (options = {})=>{
|
|
|
151
151
|
});
|
|
152
152
|
} else {
|
|
153
153
|
if (typeof item === 'string') {
|
|
154
|
-
items.unshift(create$
|
|
154
|
+
items.unshift(create$c(item, itemOptions));
|
|
155
155
|
} else {
|
|
156
156
|
items.unshift(item);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
return section
|
|
159
|
+
return section;
|
|
160
160
|
};
|
|
161
161
|
const insert = (index, item, options = {})=>{
|
|
162
|
-
let itemOptions =
|
|
162
|
+
let itemOptions = WeightedOptionsSchema.parse(options);
|
|
163
163
|
itemOptions = {
|
|
164
164
|
...sectionItemOptions,
|
|
165
165
|
...itemOptions
|
|
@@ -170,39 +170,39 @@ const create$4 = (options = {})=>{
|
|
|
170
170
|
});
|
|
171
171
|
} else {
|
|
172
172
|
if (typeof item === 'string') {
|
|
173
|
-
items.splice(index, 0, create$
|
|
173
|
+
items.splice(index, 0, create$c(item, itemOptions));
|
|
174
174
|
} else {
|
|
175
175
|
items.splice(index, 0, item);
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
-
return section
|
|
178
|
+
return section;
|
|
179
179
|
};
|
|
180
180
|
const remove = (index)=>{
|
|
181
181
|
items.splice(index, 1);
|
|
182
|
-
return section
|
|
182
|
+
return section;
|
|
183
183
|
};
|
|
184
184
|
const replace = (index, item, options = {})=>{
|
|
185
|
-
let itemOptions =
|
|
185
|
+
let itemOptions = WeightedOptionsSchema.parse(options);
|
|
186
186
|
itemOptions = {
|
|
187
187
|
...sectionItemOptions,
|
|
188
188
|
...itemOptions
|
|
189
189
|
};
|
|
190
190
|
if (typeof item === 'string') {
|
|
191
|
-
items[index] = create$
|
|
191
|
+
items[index] = create$c(item, itemOptions);
|
|
192
192
|
} else {
|
|
193
193
|
items[index] = item;
|
|
194
194
|
}
|
|
195
|
-
return section
|
|
195
|
+
return section;
|
|
196
196
|
};
|
|
197
197
|
const add = (item, options = {})=>{
|
|
198
|
-
let itemOptions =
|
|
198
|
+
let itemOptions = WeightedOptionsSchema.parse(options);
|
|
199
199
|
itemOptions = {
|
|
200
200
|
...sectionItemOptions,
|
|
201
201
|
...itemOptions
|
|
202
202
|
};
|
|
203
203
|
return append(item, itemOptions);
|
|
204
204
|
};
|
|
205
|
-
const section
|
|
205
|
+
const section = {
|
|
206
206
|
title: sectionOptions.title,
|
|
207
207
|
items,
|
|
208
208
|
weight: sectionOptions.weight,
|
|
@@ -213,15 +213,15 @@ const create$4 = (options = {})=>{
|
|
|
213
213
|
remove,
|
|
214
214
|
replace
|
|
215
215
|
};
|
|
216
|
-
return section
|
|
216
|
+
return section;
|
|
217
217
|
};
|
|
218
218
|
|
|
219
|
-
const create$
|
|
220
|
-
const weightedOptions =
|
|
221
|
-
return create$
|
|
219
|
+
const create$7 = (text, options = {})=>{
|
|
220
|
+
const weightedOptions = WeightedOptionsSchema.parse(options);
|
|
221
|
+
return create$c(text, weightedOptions);
|
|
222
222
|
};
|
|
223
223
|
|
|
224
|
-
const create$
|
|
224
|
+
const create$6 = ({ persona, instructions, contents, contexts })=>{
|
|
225
225
|
return {
|
|
226
226
|
persona,
|
|
227
227
|
instructions,
|
|
@@ -230,8 +230,8 @@ const create$2 = ({ persona, instructions, contents, contexts })=>{
|
|
|
230
230
|
};
|
|
231
231
|
};
|
|
232
232
|
|
|
233
|
-
const
|
|
234
|
-
const
|
|
233
|
+
const DEFAULT_CHARACTER_ENCODING = "utf8";
|
|
234
|
+
const LIBRARY_NAME = "riotprompt";
|
|
235
235
|
const DEFAULT_PERSONA_ROLE = "developer";
|
|
236
236
|
const DEFAULT_IGNORE_PATTERNS = [
|
|
237
237
|
"^\\..*",
|
|
@@ -280,8 +280,10 @@ const DEFAULT_LOGGER = {
|
|
|
280
280
|
info: (message, ...args)=>console.info(message, ...args),
|
|
281
281
|
warn: (message, ...args)=>console.warn(message, ...args),
|
|
282
282
|
error: (message, ...args)=>console.error(message, ...args),
|
|
283
|
-
|
|
284
|
-
|
|
283
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
284
|
+
verbose: (message, ...args)=>{},
|
|
285
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
286
|
+
silly: (message, ...args)=>{}
|
|
285
287
|
};
|
|
286
288
|
const wrapLogger = (toWrap, name)=>{
|
|
287
289
|
const requiredMethods = [
|
|
@@ -297,7 +299,7 @@ const wrapLogger = (toWrap, name)=>{
|
|
|
297
299
|
throw new Error(`Logger is missing required methods: ${missingMethods.join(', ')}`);
|
|
298
300
|
}
|
|
299
301
|
const log = (level, message, ...args)=>{
|
|
300
|
-
message = `[${
|
|
302
|
+
message = `[${LIBRARY_NAME}] ${name ? `[${name}]` : ''}: ${message}`;
|
|
301
303
|
if (level === 'debug') toWrap.debug(message, ...args);
|
|
302
304
|
else if (level === 'info') toWrap.info(message, ...args);
|
|
303
305
|
else if (level === 'warn') toWrap.warn(message, ...args);
|
|
@@ -389,7 +391,7 @@ function isSection(obj) {
|
|
|
389
391
|
function isWeighted(obj) {
|
|
390
392
|
return obj && typeof obj === 'object' && 'text' in obj;
|
|
391
393
|
}
|
|
392
|
-
const
|
|
394
|
+
const create$5 = (formatterOptions)=>{
|
|
393
395
|
const options = OptionSchema$1.parse(formatterOptions || {});
|
|
394
396
|
const logger = wrapLogger(options.logger, 'Formatter');
|
|
395
397
|
let formatOptions = DEFAULT_FORMAT_OPTIONS;
|
|
@@ -490,7 +492,7 @@ const formatter = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty(
|
|
|
490
492
|
OptionSchema: OptionSchema$1,
|
|
491
493
|
SectionSeparatorSchema,
|
|
492
494
|
SectionTitlePropertySchema,
|
|
493
|
-
create:
|
|
495
|
+
create: create$5
|
|
494
496
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
495
497
|
|
|
496
498
|
const parseMarkdown = (input, options = {})=>{
|
|
@@ -500,11 +502,11 @@ const parseMarkdown = (input, options = {})=>{
|
|
|
500
502
|
} else {
|
|
501
503
|
markdownContent = input.toString();
|
|
502
504
|
}
|
|
503
|
-
const sectionOptions =
|
|
505
|
+
const sectionOptions = SectionOptionsSchema.parse(options);
|
|
504
506
|
// Use marked.lexer to get tokens without full parsing/rendering
|
|
505
507
|
const tokens = marked.marked.lexer(markdownContent);
|
|
506
508
|
// Create the main section (with a Title from the options)
|
|
507
|
-
const mainSection = create$
|
|
509
|
+
const mainSection = create$8(sectionOptions);
|
|
508
510
|
// Track sections at each depth level
|
|
509
511
|
const sectionStack = [
|
|
510
512
|
mainSection
|
|
@@ -512,7 +514,7 @@ const parseMarkdown = (input, options = {})=>{
|
|
|
512
514
|
// Set if we've seen the first token
|
|
513
515
|
let isFirstToken = true;
|
|
514
516
|
// Set the item options
|
|
515
|
-
const itemOptions =
|
|
517
|
+
const itemOptions = WeightedOptionsSchema.parse({
|
|
516
518
|
...sectionOptions,
|
|
517
519
|
weight: sectionOptions.itemWeight
|
|
518
520
|
});
|
|
@@ -529,7 +531,7 @@ const parseMarkdown = (input, options = {})=>{
|
|
|
529
531
|
}
|
|
530
532
|
isFirstToken = false;
|
|
531
533
|
// Create a new section with this heading
|
|
532
|
-
const newSection = create$
|
|
534
|
+
const newSection = create$8({
|
|
533
535
|
...sectionOptions,
|
|
534
536
|
title: token.text
|
|
535
537
|
});
|
|
@@ -555,7 +557,7 @@ const parseMarkdown = (input, options = {})=>{
|
|
|
555
557
|
case 'paragraph':
|
|
556
558
|
{
|
|
557
559
|
isFirstToken = false;
|
|
558
|
-
const instruction = create$
|
|
560
|
+
const instruction = create$c(token.text, itemOptions);
|
|
559
561
|
const currentSection = sectionStack[sectionStack.length - 1];
|
|
560
562
|
currentSection.add(instruction, itemOptions);
|
|
561
563
|
break;
|
|
@@ -565,7 +567,7 @@ const parseMarkdown = (input, options = {})=>{
|
|
|
565
567
|
isFirstToken = false;
|
|
566
568
|
// Convert list items to instructions
|
|
567
569
|
const listInstructionContent = token.items.map((item)=>`- ${item.text}`).join('\n');
|
|
568
|
-
const listInstruction = create$
|
|
570
|
+
const listInstruction = create$c(listInstructionContent, itemOptions);
|
|
569
571
|
const currentSection = sectionStack[sectionStack.length - 1];
|
|
570
572
|
currentSection.add(listInstruction, itemOptions);
|
|
571
573
|
break;
|
|
@@ -574,7 +576,7 @@ const parseMarkdown = (input, options = {})=>{
|
|
|
574
576
|
{
|
|
575
577
|
isFirstToken = false;
|
|
576
578
|
// Represent code blocks as instructions
|
|
577
|
-
const codeInstruction = create$
|
|
579
|
+
const codeInstruction = create$c(`\`\`\`${token.lang || ''}\n${token.text}\n\`\`\``, itemOptions);
|
|
578
580
|
const currentSection = sectionStack[sectionStack.length - 1];
|
|
579
581
|
currentSection.add(codeInstruction, itemOptions);
|
|
580
582
|
break;
|
|
@@ -586,7 +588,7 @@ const parseMarkdown = (input, options = {})=>{
|
|
|
586
588
|
isFirstToken = false;
|
|
587
589
|
// Treat other block tokens' text as instructions for robustness
|
|
588
590
|
if ('text' in token && token.text) {
|
|
589
|
-
const fallbackInstruction = create$
|
|
591
|
+
const fallbackInstruction = create$c(token.text, itemOptions);
|
|
590
592
|
const currentSection = sectionStack[sectionStack.length - 1];
|
|
591
593
|
currentSection.add(fallbackInstruction, itemOptions);
|
|
592
594
|
}
|
|
@@ -604,18 +606,18 @@ const parseText = (input, options = {})=>{
|
|
|
604
606
|
} else {
|
|
605
607
|
text = input.toString();
|
|
606
608
|
}
|
|
607
|
-
const sectionOptions =
|
|
609
|
+
const sectionOptions = SectionOptionsSchema.parse(options);
|
|
608
610
|
// Set the item options
|
|
609
|
-
const itemOptions =
|
|
611
|
+
const itemOptions = WeightedOptionsSchema.parse({
|
|
610
612
|
...sectionOptions,
|
|
611
613
|
weight: sectionOptions.itemWeight
|
|
612
614
|
});
|
|
613
615
|
// Split the text on newlines
|
|
614
616
|
const lines = text.split(/\r?\n/).filter((line)=>line.trim().length > 0);
|
|
615
617
|
// Create the main section with the supplied title
|
|
616
|
-
const mainSection = create$
|
|
618
|
+
const mainSection = create$8(sectionOptions);
|
|
617
619
|
for (const line of lines){
|
|
618
|
-
const instruction = create$
|
|
620
|
+
const instruction = create$c(line, itemOptions);
|
|
619
621
|
mainSection.add(instruction, itemOptions);
|
|
620
622
|
}
|
|
621
623
|
return mainSection;
|
|
@@ -634,7 +636,7 @@ const markdownRegex = /^(#+\s|\*\s|-\s|\+\s|>\s|\[.*\]\(.*\)|```|~~~|---\\s*$)/m
|
|
|
634
636
|
return false;
|
|
635
637
|
}
|
|
636
638
|
// Convert Buffer to string if necessary
|
|
637
|
-
const content = typeof input === 'string' ? input : input.toString(
|
|
639
|
+
const content = typeof input === 'string' ? input : input.toString(DEFAULT_CHARACTER_ENCODING);
|
|
638
640
|
if (!content || content.trim() === '') {
|
|
639
641
|
return false; // Empty string is not considered Markdown
|
|
640
642
|
}
|
|
@@ -732,7 +734,7 @@ const markdownRegex = /^(#+\s|\*\s|-\s|\+\s|>\s|\[.*\]\(.*\)|```|~~~|---\\s*$)/m
|
|
|
732
734
|
function isText(input) {
|
|
733
735
|
let buf;
|
|
734
736
|
if (typeof input === 'string') {
|
|
735
|
-
buf = Buffer.from(input,
|
|
737
|
+
buf = Buffer.from(input, DEFAULT_CHARACTER_ENCODING);
|
|
736
738
|
} else {
|
|
737
739
|
buf = input;
|
|
738
740
|
}
|
|
@@ -746,7 +748,7 @@ function isText(input) {
|
|
|
746
748
|
}
|
|
747
749
|
// For UTF-8 encoded text (including emoji and international characters),
|
|
748
750
|
// convert to string first and check if there are non-printable characters
|
|
749
|
-
const str = buf.toString(
|
|
751
|
+
const str = buf.toString(DEFAULT_CHARACTER_ENCODING);
|
|
750
752
|
// Count the number of non-printable ASCII characters (excluding common whitespace)
|
|
751
753
|
let nonPrintable = 0;
|
|
752
754
|
const len = Math.min(str.length, 512); // Only check the first 512 characters for performance
|
|
@@ -764,14 +766,14 @@ function isText(input) {
|
|
|
764
766
|
|
|
765
767
|
const OptionsSchema$2 = zod.z.object({
|
|
766
768
|
logger: zod.z.any().optional().default(DEFAULT_LOGGER),
|
|
767
|
-
parameters:
|
|
769
|
+
parameters: ParametersSchema.optional().default({})
|
|
768
770
|
});
|
|
769
|
-
const
|
|
771
|
+
const create$4 = (parserOptions)=>{
|
|
770
772
|
const options = OptionsSchema$2.parse(parserOptions || {});
|
|
771
773
|
const parameters = options.parameters;
|
|
772
774
|
const logger = wrapLogger(options.logger, 'Parser');
|
|
773
775
|
const loadOptions = (sectionOptions = {})=>{
|
|
774
|
-
const currentOptions =
|
|
776
|
+
const currentOptions = SectionOptionsSchema.parse(sectionOptions);
|
|
775
777
|
return {
|
|
776
778
|
...currentOptions,
|
|
777
779
|
parameters: {
|
|
@@ -826,11 +828,11 @@ const parser.create = (parserOptions)=>{
|
|
|
826
828
|
|
|
827
829
|
const parser = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
828
830
|
__proto__: null,
|
|
829
|
-
create:
|
|
831
|
+
create: create$4
|
|
830
832
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
831
833
|
|
|
832
834
|
// eslint-disable-next-line no-restricted-imports
|
|
833
|
-
const create$
|
|
835
|
+
const create$3 = (params)=>{
|
|
834
836
|
// eslint-disable-next-line no-console
|
|
835
837
|
const log = params.log || console.log;
|
|
836
838
|
const exists = async (path)=>{
|
|
@@ -957,7 +959,7 @@ const create$1 = (params)=>{
|
|
|
957
959
|
const OptionsSchema$1 = zod.z.object({
|
|
958
960
|
logger: zod.z.any().optional().default(DEFAULT_LOGGER),
|
|
959
961
|
ignorePatterns: zod.z.array(zod.z.string()).optional().default(DEFAULT_IGNORE_PATTERNS),
|
|
960
|
-
parameters:
|
|
962
|
+
parameters: ParametersSchema.optional().default({})
|
|
961
963
|
});
|
|
962
964
|
/**
|
|
963
965
|
* Extracts the first header from Markdown text
|
|
@@ -985,13 +987,13 @@ const OptionsSchema$1 = zod.z.object({
|
|
|
985
987
|
}
|
|
986
988
|
return markdownText;
|
|
987
989
|
}
|
|
988
|
-
const
|
|
990
|
+
const create$2 = (loaderOptions)=>{
|
|
989
991
|
const options = OptionsSchema$1.parse(loaderOptions || {});
|
|
990
992
|
const parameters = options.parameters;
|
|
991
993
|
const logger = wrapLogger(options.logger, 'Loader');
|
|
992
994
|
const ignorePatterns = options.ignorePatterns;
|
|
993
995
|
const loadOptions = (sectionOptions = {})=>{
|
|
994
|
-
const currentOptions =
|
|
996
|
+
const currentOptions = SectionOptionsSchema.parse(sectionOptions);
|
|
995
997
|
return {
|
|
996
998
|
...currentOptions,
|
|
997
999
|
parameters: {
|
|
@@ -1013,7 +1015,7 @@ const loader.create = (loaderOptions)=>{
|
|
|
1013
1015
|
logger.debug(`No context directories provided, returning empty context`);
|
|
1014
1016
|
return contextSections;
|
|
1015
1017
|
}
|
|
1016
|
-
const storage = create$
|
|
1018
|
+
const storage = create$3({
|
|
1017
1019
|
log: logger.debug
|
|
1018
1020
|
});
|
|
1019
1021
|
// Add context sections from each directory
|
|
@@ -1031,7 +1033,7 @@ const loader.create = (loaderOptions)=>{
|
|
|
1031
1033
|
const firstHeader = extractFirstHeader(mainContextContent);
|
|
1032
1034
|
// Use the header from context.md as the section title, or fallback to directory name
|
|
1033
1035
|
const sectionTitle = firstHeader || dirName;
|
|
1034
|
-
mainContextSection = create$
|
|
1036
|
+
mainContextSection = create$8({
|
|
1035
1037
|
...sectionOptions,
|
|
1036
1038
|
title: sectionTitle
|
|
1037
1039
|
});
|
|
@@ -1047,7 +1049,7 @@ const loader.create = (loaderOptions)=>{
|
|
|
1047
1049
|
}
|
|
1048
1050
|
} else {
|
|
1049
1051
|
// If no context.md exists, use directory name as title
|
|
1050
|
-
mainContextSection = create$
|
|
1052
|
+
mainContextSection = create$8({
|
|
1051
1053
|
...sectionOptions,
|
|
1052
1054
|
title: dirName
|
|
1053
1055
|
});
|
|
@@ -1075,7 +1077,7 @@ const loader.create = (loaderOptions)=>{
|
|
|
1075
1077
|
}
|
|
1076
1078
|
}
|
|
1077
1079
|
// Create a subsection with the extracted name
|
|
1078
|
-
const fileSection = create$
|
|
1080
|
+
const fileSection = create$8({
|
|
1079
1081
|
...sectionOptions,
|
|
1080
1082
|
title: sectionName
|
|
1081
1083
|
});
|
|
@@ -1102,26 +1104,28 @@ const loader.create = (loaderOptions)=>{
|
|
|
1102
1104
|
|
|
1103
1105
|
const loader = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
1104
1106
|
__proto__: null,
|
|
1105
|
-
create:
|
|
1107
|
+
create: create$2,
|
|
1106
1108
|
extractFirstHeader,
|
|
1107
1109
|
removeFirstHeader
|
|
1108
1110
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
1109
1111
|
|
|
1110
1112
|
const OptionsSchema = zod.z.object({
|
|
1111
1113
|
logger: zod.z.any().optional().default(DEFAULT_LOGGER),
|
|
1112
|
-
|
|
1114
|
+
configDirs: zod.z.array(zod.z.string()).default([
|
|
1115
|
+
'./overrides'
|
|
1116
|
+
]),
|
|
1113
1117
|
overrides: zod.z.boolean().default(false),
|
|
1114
|
-
parameters:
|
|
1118
|
+
parameters: ParametersSchema.optional().default({})
|
|
1115
1119
|
});
|
|
1116
|
-
const
|
|
1120
|
+
const create$1 = (overrideOptions = {})=>{
|
|
1117
1121
|
const options = OptionsSchema.parse(overrideOptions);
|
|
1118
1122
|
const parameters = options.parameters;
|
|
1119
1123
|
const logger = wrapLogger(options === null || options === void 0 ? void 0 : options.logger, 'Override');
|
|
1120
|
-
const storage = create$
|
|
1124
|
+
const storage = create$3({
|
|
1121
1125
|
log: logger.debug
|
|
1122
1126
|
});
|
|
1123
1127
|
const loadOptions = (sectionOptions = {})=>{
|
|
1124
|
-
const currentOptions =
|
|
1128
|
+
const currentOptions = SectionOptionsSchema.parse(sectionOptions);
|
|
1125
1129
|
return {
|
|
1126
1130
|
...currentOptions,
|
|
1127
1131
|
parameters: {
|
|
@@ -1132,42 +1136,54 @@ const override.create = (overrideOptions = {})=>{
|
|
|
1132
1136
|
};
|
|
1133
1137
|
const override = async (overrideFile, section, sectionOptions = {})=>{
|
|
1134
1138
|
const currentSectionOptions = loadOptions(sectionOptions);
|
|
1135
|
-
const
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
const
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
logger
|
|
1150
|
-
});
|
|
1151
|
-
response.append = await parser$1.parseFile(postFile, currentSectionOptions);
|
|
1152
|
-
}
|
|
1153
|
-
if (await storage.exists(baseFile)) {
|
|
1154
|
-
logger.silly('Found base file %s', baseFile);
|
|
1155
|
-
if (options.overrides) {
|
|
1156
|
-
logger.warn('WARNING: Core directives are being overwritten by custom configuration');
|
|
1157
|
-
const parser$1 = parser.create({
|
|
1139
|
+
const response = {
|
|
1140
|
+
prepends: [],
|
|
1141
|
+
appends: []
|
|
1142
|
+
};
|
|
1143
|
+
// Process directories in order (closest to furthest)
|
|
1144
|
+
for(let i = 0; i < options.configDirs.length; i++){
|
|
1145
|
+
const configDir = options.configDirs[i];
|
|
1146
|
+
const baseFile = path.join(configDir, overrideFile);
|
|
1147
|
+
const preFile = baseFile.replace('.md', '-pre.md');
|
|
1148
|
+
const postFile = baseFile.replace('.md', '-post.md');
|
|
1149
|
+
// Check for prepend files (-pre.md)
|
|
1150
|
+
if (await storage.exists(preFile)) {
|
|
1151
|
+
logger.silly('Found pre file %s (layer %d)', preFile, i + 1);
|
|
1152
|
+
const parser$1 = create$4({
|
|
1158
1153
|
logger
|
|
1159
1154
|
});
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1155
|
+
const prependSection = await parser$1.parseFile(preFile, currentSectionOptions);
|
|
1156
|
+
response.prepends.push(prependSection);
|
|
1157
|
+
}
|
|
1158
|
+
// Check for append files (-post.md)
|
|
1159
|
+
if (await storage.exists(postFile)) {
|
|
1160
|
+
logger.silly('Found post file %s (layer %d)', postFile, i + 1);
|
|
1161
|
+
const parser$1 = create$4({
|
|
1162
|
+
logger
|
|
1163
|
+
});
|
|
1164
|
+
const appendSection = await parser$1.parseFile(postFile, currentSectionOptions);
|
|
1165
|
+
response.appends.push(appendSection);
|
|
1166
|
+
}
|
|
1167
|
+
// Check for complete override files - use the first (closest) one found
|
|
1168
|
+
if (!response.override && await storage.exists(baseFile)) {
|
|
1169
|
+
logger.silly('Found base file %s (layer %d)', baseFile, i + 1);
|
|
1170
|
+
if (options.overrides) {
|
|
1171
|
+
logger.warn('WARNING: Core directives are being overwritten by custom configuration at layer %d', i + 1);
|
|
1172
|
+
const parser$1 = create$4({
|
|
1173
|
+
logger
|
|
1174
|
+
});
|
|
1175
|
+
response.override = await parser$1.parseFile(baseFile, currentSectionOptions);
|
|
1176
|
+
} else {
|
|
1177
|
+
logger.error('ERROR: Core directives are being overwritten by custom configuration');
|
|
1178
|
+
throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
|
|
1179
|
+
}
|
|
1164
1180
|
}
|
|
1165
1181
|
}
|
|
1166
1182
|
return response;
|
|
1167
1183
|
};
|
|
1168
1184
|
const customize = async (overrideFile, section, sectionOptions = {})=>{
|
|
1169
1185
|
const currentSectionOptions = loadOptions(sectionOptions);
|
|
1170
|
-
const { overrideContent,
|
|
1186
|
+
const { override: overrideContent, prepends, appends } = await override(overrideFile, section, currentSectionOptions);
|
|
1171
1187
|
let finalSection = section;
|
|
1172
1188
|
if (overrideContent) {
|
|
1173
1189
|
if (options.overrides) {
|
|
@@ -1178,15 +1194,17 @@ const override.create = (overrideOptions = {})=>{
|
|
|
1178
1194
|
throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
|
|
1179
1195
|
}
|
|
1180
1196
|
}
|
|
1181
|
-
|
|
1197
|
+
// Apply prepends in order (closest layer first)
|
|
1198
|
+
for (const prepend of prepends){
|
|
1182
1199
|
logger.silly('Prepend found, adding to content from file %s', prepend);
|
|
1183
1200
|
finalSection = finalSection.prepend(prepend);
|
|
1184
1201
|
}
|
|
1185
|
-
|
|
1202
|
+
// Apply appends in reverse order (furthest layers first, then closest)
|
|
1203
|
+
for (const append of appends.reverse()){
|
|
1186
1204
|
logger.silly('Append found, adding to content from file %s', append);
|
|
1187
1205
|
finalSection = finalSection.append(append);
|
|
1188
1206
|
}
|
|
1189
|
-
const formatter$1 =
|
|
1207
|
+
const formatter$1 = create$5({
|
|
1190
1208
|
logger
|
|
1191
1209
|
});
|
|
1192
1210
|
logger.silly('Final section %s:\n\n%s\n\n', logger.name, formatter$1.format(finalSection));
|
|
@@ -1200,46 +1218,50 @@ const override.create = (overrideOptions = {})=>{
|
|
|
1200
1218
|
|
|
1201
1219
|
const override = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
1202
1220
|
__proto__: null,
|
|
1203
|
-
create:
|
|
1221
|
+
create: create$1
|
|
1204
1222
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
1205
1223
|
|
|
1206
1224
|
const OptionSchema = zod.z.object({
|
|
1207
1225
|
logger: zod.z.any().optional().default(DEFAULT_LOGGER),
|
|
1208
1226
|
basePath: zod.z.string(),
|
|
1209
|
-
|
|
1227
|
+
overridePaths: zod.z.array(zod.z.string()).optional().default([
|
|
1228
|
+
"./"
|
|
1229
|
+
]),
|
|
1210
1230
|
overrides: zod.z.boolean().optional().default(false),
|
|
1211
|
-
parameters:
|
|
1231
|
+
parameters: ParametersSchema.optional().default({})
|
|
1212
1232
|
});
|
|
1213
1233
|
const create = (builderOptions)=>{
|
|
1214
1234
|
const options = OptionSchema.parse(builderOptions);
|
|
1215
1235
|
const logger = wrapLogger(options.logger, 'Builder');
|
|
1216
|
-
const parser$1 =
|
|
1236
|
+
const parser$1 = create$4({
|
|
1217
1237
|
logger
|
|
1218
1238
|
});
|
|
1219
|
-
const override$1 =
|
|
1239
|
+
const override$1 = create$1({
|
|
1220
1240
|
logger,
|
|
1221
|
-
|
|
1241
|
+
configDirs: options.overridePaths || [
|
|
1242
|
+
"./"
|
|
1243
|
+
],
|
|
1222
1244
|
overrides: options.overrides || false
|
|
1223
1245
|
});
|
|
1224
|
-
const loader$1 =
|
|
1246
|
+
const loader$1 = create$2({
|
|
1225
1247
|
logger
|
|
1226
1248
|
});
|
|
1227
|
-
const personaSection = create$
|
|
1249
|
+
const personaSection = create$8({
|
|
1228
1250
|
title: "Persona"
|
|
1229
1251
|
});
|
|
1230
|
-
const contextSection = create$
|
|
1252
|
+
const contextSection = create$8({
|
|
1231
1253
|
title: "Context"
|
|
1232
1254
|
});
|
|
1233
|
-
const instructionSection = create$
|
|
1255
|
+
const instructionSection = create$8({
|
|
1234
1256
|
title: "Instruction"
|
|
1235
1257
|
});
|
|
1236
|
-
const contentSection = create$
|
|
1258
|
+
const contentSection = create$8({
|
|
1237
1259
|
title: "Content"
|
|
1238
1260
|
});
|
|
1239
1261
|
const parameters = options.parameters;
|
|
1240
1262
|
const instance = {};
|
|
1241
1263
|
const loadOptions = (sectionOptions = {})=>{
|
|
1242
|
-
const currentOptions =
|
|
1264
|
+
const currentOptions = SectionOptionsSchema.parse(sectionOptions);
|
|
1243
1265
|
return {
|
|
1244
1266
|
...currentOptions,
|
|
1245
1267
|
parameters: {
|
|
@@ -1325,7 +1347,7 @@ const create = (builderOptions)=>{
|
|
|
1325
1347
|
instance.addContext = addContext;
|
|
1326
1348
|
const build = async ()=>{
|
|
1327
1349
|
logger.debug("Building prompt", {});
|
|
1328
|
-
const prompt = create$
|
|
1350
|
+
const prompt = create$6({
|
|
1329
1351
|
persona: personaSection,
|
|
1330
1352
|
contexts: contextSection,
|
|
1331
1353
|
instructions: instructionSection,
|
|
@@ -1342,18 +1364,450 @@ const builder = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
|
1342
1364
|
create
|
|
1343
1365
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
1344
1366
|
|
|
1367
|
+
// ===== CONFIGURATION SCHEMAS =====
|
|
1368
|
+
const ContentItemSchema = zod.z.union([
|
|
1369
|
+
zod.z.string(),
|
|
1370
|
+
zod.z.object({
|
|
1371
|
+
content: zod.z.string(),
|
|
1372
|
+
title: zod.z.string().optional(),
|
|
1373
|
+
weight: zod.z.number().optional()
|
|
1374
|
+
}),
|
|
1375
|
+
zod.z.object({
|
|
1376
|
+
path: zod.z.string(),
|
|
1377
|
+
title: zod.z.string().optional(),
|
|
1378
|
+
weight: zod.z.number().optional()
|
|
1379
|
+
}),
|
|
1380
|
+
zod.z.object({
|
|
1381
|
+
directories: zod.z.array(zod.z.string()),
|
|
1382
|
+
title: zod.z.string().optional(),
|
|
1383
|
+
weight: zod.z.number().optional()
|
|
1384
|
+
})
|
|
1385
|
+
]);
|
|
1386
|
+
const RecipeConfigSchema = zod.z.object({
|
|
1387
|
+
// Core settings
|
|
1388
|
+
basePath: zod.z.string(),
|
|
1389
|
+
logger: zod.z.any().optional().default(DEFAULT_LOGGER),
|
|
1390
|
+
overridePaths: zod.z.array(zod.z.string()).optional().default([
|
|
1391
|
+
"./"
|
|
1392
|
+
]),
|
|
1393
|
+
overrides: zod.z.boolean().optional().default(false),
|
|
1394
|
+
parameters: ParametersSchema.optional().default({}),
|
|
1395
|
+
// Content sections - smart inference based on naming
|
|
1396
|
+
persona: ContentItemSchema.optional(),
|
|
1397
|
+
instructions: zod.z.array(ContentItemSchema).optional().default([]),
|
|
1398
|
+
content: zod.z.array(ContentItemSchema).optional().default([]),
|
|
1399
|
+
context: zod.z.array(ContentItemSchema).optional().default([]),
|
|
1400
|
+
// Templates and inheritance
|
|
1401
|
+
extends: zod.z.string().optional(),
|
|
1402
|
+
template: zod.z.enum([
|
|
1403
|
+
'commit',
|
|
1404
|
+
'release',
|
|
1405
|
+
'documentation',
|
|
1406
|
+
'review',
|
|
1407
|
+
'custom'
|
|
1408
|
+
]).optional()
|
|
1409
|
+
});
|
|
1410
|
+
// Built-in template configurations matching common patterns
|
|
1411
|
+
const DEFAULT_TEMPLATES = {
|
|
1412
|
+
commit: {
|
|
1413
|
+
persona: {
|
|
1414
|
+
path: "personas/developer.md",
|
|
1415
|
+
title: "Developer Persona"
|
|
1416
|
+
},
|
|
1417
|
+
instructions: [
|
|
1418
|
+
{
|
|
1419
|
+
path: "instructions/commit.md",
|
|
1420
|
+
title: "Commit Instructions"
|
|
1421
|
+
}
|
|
1422
|
+
]
|
|
1423
|
+
},
|
|
1424
|
+
release: {
|
|
1425
|
+
persona: {
|
|
1426
|
+
path: "personas/releaser.md",
|
|
1427
|
+
title: "Release Manager Persona"
|
|
1428
|
+
},
|
|
1429
|
+
instructions: [
|
|
1430
|
+
{
|
|
1431
|
+
path: "instructions/release.md",
|
|
1432
|
+
title: "Release Instructions"
|
|
1433
|
+
}
|
|
1434
|
+
]
|
|
1435
|
+
},
|
|
1436
|
+
documentation: {
|
|
1437
|
+
persona: {
|
|
1438
|
+
path: "personas/technical-writer.md",
|
|
1439
|
+
title: "Technical Writer Persona"
|
|
1440
|
+
},
|
|
1441
|
+
instructions: [
|
|
1442
|
+
{
|
|
1443
|
+
path: "instructions/documentation.md",
|
|
1444
|
+
title: "Documentation Instructions"
|
|
1445
|
+
}
|
|
1446
|
+
]
|
|
1447
|
+
},
|
|
1448
|
+
review: {
|
|
1449
|
+
persona: {
|
|
1450
|
+
path: "personas/reviewer.md",
|
|
1451
|
+
title: "Code Reviewer Persona"
|
|
1452
|
+
},
|
|
1453
|
+
instructions: [
|
|
1454
|
+
{
|
|
1455
|
+
path: "instructions/review.md",
|
|
1456
|
+
title: "Review Instructions"
|
|
1457
|
+
}
|
|
1458
|
+
]
|
|
1459
|
+
}
|
|
1460
|
+
};
|
|
1461
|
+
// User-customizable template registry
|
|
1462
|
+
let TEMPLATES = {
|
|
1463
|
+
...DEFAULT_TEMPLATES
|
|
1464
|
+
};
|
|
1465
|
+
/**
|
|
1466
|
+
* Configure custom template paths (perfect for KodrDriv constants!)
|
|
1467
|
+
*
|
|
1468
|
+
* @example
|
|
1469
|
+
* ```typescript
|
|
1470
|
+
* // Configure using your KodrDriv constants
|
|
1471
|
+
* configureTemplates({
|
|
1472
|
+
* commit: {
|
|
1473
|
+
* persona: { path: DEFAULT_PERSONA_YOU_FILE },
|
|
1474
|
+
* instructions: [{ path: DEFAULT_INSTRUCTIONS_COMMIT_FILE }]
|
|
1475
|
+
* },
|
|
1476
|
+
* release: {
|
|
1477
|
+
* persona: { path: DEFAULT_PERSONA_RELEASER_FILE },
|
|
1478
|
+
* instructions: [{ path: DEFAULT_INSTRUCTIONS_RELEASE_FILE }]
|
|
1479
|
+
* }
|
|
1480
|
+
* });
|
|
1481
|
+
* ```
|
|
1482
|
+
*/ const configureTemplates = (customTemplates)=>{
|
|
1483
|
+
TEMPLATES = {
|
|
1484
|
+
...DEFAULT_TEMPLATES,
|
|
1485
|
+
...customTemplates
|
|
1486
|
+
};
|
|
1487
|
+
};
|
|
1488
|
+
/**
|
|
1489
|
+
* Get current template configuration
|
|
1490
|
+
*/ const getTemplates = ()=>({
|
|
1491
|
+
...TEMPLATES
|
|
1492
|
+
});
|
|
1493
|
+
// ===== CORE RECIPE ENGINE =====
|
|
1494
|
+
const cook = async (config)=>{
|
|
1495
|
+
// Parse and validate configuration with defaults
|
|
1496
|
+
const validatedConfig = RecipeConfigSchema.parse({
|
|
1497
|
+
overridePaths: [
|
|
1498
|
+
"./"
|
|
1499
|
+
],
|
|
1500
|
+
overrides: false,
|
|
1501
|
+
parameters: {},
|
|
1502
|
+
instructions: [],
|
|
1503
|
+
content: [],
|
|
1504
|
+
context: [],
|
|
1505
|
+
...config
|
|
1506
|
+
});
|
|
1507
|
+
// Handle template inheritance
|
|
1508
|
+
let finalConfig = {
|
|
1509
|
+
...validatedConfig
|
|
1510
|
+
};
|
|
1511
|
+
if (validatedConfig.template) {
|
|
1512
|
+
const template = TEMPLATES[validatedConfig.template];
|
|
1513
|
+
if (template) {
|
|
1514
|
+
finalConfig = {
|
|
1515
|
+
...template,
|
|
1516
|
+
...validatedConfig
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
// Setup internal services
|
|
1521
|
+
const logger = wrapLogger(finalConfig.logger, 'Recipe');
|
|
1522
|
+
const parser$1 = create$4({
|
|
1523
|
+
logger
|
|
1524
|
+
});
|
|
1525
|
+
const override$1 = create$1({
|
|
1526
|
+
logger,
|
|
1527
|
+
configDirs: finalConfig.overridePaths || [
|
|
1528
|
+
"./"
|
|
1529
|
+
],
|
|
1530
|
+
overrides: finalConfig.overrides || false
|
|
1531
|
+
});
|
|
1532
|
+
const loader$1 = create$2({
|
|
1533
|
+
logger
|
|
1534
|
+
});
|
|
1535
|
+
// Create sections
|
|
1536
|
+
const personaSection = create$8({
|
|
1537
|
+
title: "Persona"
|
|
1538
|
+
});
|
|
1539
|
+
const instructionSection = create$8({
|
|
1540
|
+
title: "Instruction"
|
|
1541
|
+
});
|
|
1542
|
+
const contentSection = create$8({
|
|
1543
|
+
title: "Content"
|
|
1544
|
+
});
|
|
1545
|
+
const contextSection = create$8({
|
|
1546
|
+
title: "Context"
|
|
1547
|
+
});
|
|
1548
|
+
// Process persona
|
|
1549
|
+
if (finalConfig.persona) {
|
|
1550
|
+
await processContentItem(finalConfig.persona, personaSection, 'persona', {
|
|
1551
|
+
basePath: finalConfig.basePath,
|
|
1552
|
+
parser: parser$1,
|
|
1553
|
+
override: override$1,
|
|
1554
|
+
loader: loader$1,
|
|
1555
|
+
parameters: finalConfig.parameters});
|
|
1556
|
+
}
|
|
1557
|
+
// Process instructions
|
|
1558
|
+
for (const item of finalConfig.instructions || []){
|
|
1559
|
+
await processContentItem(item, instructionSection, 'instruction', {
|
|
1560
|
+
basePath: finalConfig.basePath,
|
|
1561
|
+
parser: parser$1,
|
|
1562
|
+
override: override$1,
|
|
1563
|
+
loader: loader$1,
|
|
1564
|
+
parameters: finalConfig.parameters});
|
|
1565
|
+
}
|
|
1566
|
+
// Process content
|
|
1567
|
+
for (const item of finalConfig.content || []){
|
|
1568
|
+
await processContentItem(item, contentSection, 'content', {
|
|
1569
|
+
basePath: finalConfig.basePath,
|
|
1570
|
+
parser: parser$1,
|
|
1571
|
+
override: override$1,
|
|
1572
|
+
loader: loader$1,
|
|
1573
|
+
parameters: finalConfig.parameters});
|
|
1574
|
+
}
|
|
1575
|
+
// Process context
|
|
1576
|
+
for (const item of finalConfig.context || []){
|
|
1577
|
+
await processContentItem(item, contextSection, 'context', {
|
|
1578
|
+
basePath: finalConfig.basePath,
|
|
1579
|
+
parser: parser$1,
|
|
1580
|
+
override: override$1,
|
|
1581
|
+
loader: loader$1,
|
|
1582
|
+
parameters: finalConfig.parameters});
|
|
1583
|
+
}
|
|
1584
|
+
// Build and return prompt
|
|
1585
|
+
return create$6({
|
|
1586
|
+
persona: personaSection,
|
|
1587
|
+
instructions: instructionSection,
|
|
1588
|
+
contents: contentSection,
|
|
1589
|
+
contexts: contextSection
|
|
1590
|
+
});
|
|
1591
|
+
};
|
|
1592
|
+
const processContentItem = async (item, section, type, ctx)=>{
|
|
1593
|
+
const sectionOptions = {
|
|
1594
|
+
parameters: ctx.parameters
|
|
1595
|
+
};
|
|
1596
|
+
if (typeof item === 'string') {
|
|
1597
|
+
// Simple string content
|
|
1598
|
+
const parsedSection = ctx.parser.parse(item, sectionOptions);
|
|
1599
|
+
section.add(parsedSection);
|
|
1600
|
+
} else if ('content' in item) {
|
|
1601
|
+
// Inline content with options
|
|
1602
|
+
const parsedSection = ctx.parser.parse(item.content, {
|
|
1603
|
+
...sectionOptions,
|
|
1604
|
+
title: item.title,
|
|
1605
|
+
weight: item.weight
|
|
1606
|
+
});
|
|
1607
|
+
section.add(parsedSection);
|
|
1608
|
+
} else if ('path' in item) {
|
|
1609
|
+
// File path
|
|
1610
|
+
const fullPath = path.join(ctx.basePath, item.path);
|
|
1611
|
+
const parsedSection = await ctx.parser.parseFile(fullPath, {
|
|
1612
|
+
...sectionOptions,
|
|
1613
|
+
title: item.title,
|
|
1614
|
+
weight: item.weight
|
|
1615
|
+
});
|
|
1616
|
+
const overrideSection = await ctx.override.customize(item.path, parsedSection, sectionOptions);
|
|
1617
|
+
section.add(overrideSection);
|
|
1618
|
+
} else if ('directories' in item) {
|
|
1619
|
+
// Directory loading
|
|
1620
|
+
const sections = await ctx.loader.load(item.directories, {
|
|
1621
|
+
...sectionOptions,
|
|
1622
|
+
title: item.title,
|
|
1623
|
+
weight: item.weight
|
|
1624
|
+
});
|
|
1625
|
+
section.add(sections);
|
|
1626
|
+
}
|
|
1627
|
+
};
|
|
1628
|
+
// ===== CONVENIENCE FUNCTIONS =====
|
|
1629
|
+
const commit = (config)=>cook({
|
|
1630
|
+
...config,
|
|
1631
|
+
template: 'commit'
|
|
1632
|
+
});
|
|
1633
|
+
const release = (config)=>cook({
|
|
1634
|
+
...config,
|
|
1635
|
+
template: 'release'
|
|
1636
|
+
});
|
|
1637
|
+
const documentation = (config)=>cook({
|
|
1638
|
+
...config,
|
|
1639
|
+
template: 'documentation'
|
|
1640
|
+
});
|
|
1641
|
+
const review = (config)=>cook({
|
|
1642
|
+
...config,
|
|
1643
|
+
template: 'review'
|
|
1644
|
+
});
|
|
1645
|
+
// ===== QUICK BUILDERS =====
|
|
1646
|
+
const quick = {
|
|
1647
|
+
/**
|
|
1648
|
+
* Create a commit prompt with minimal configuration
|
|
1649
|
+
*/ commit: async (diffContent, options)=>{
|
|
1650
|
+
return cook({
|
|
1651
|
+
basePath: options.basePath,
|
|
1652
|
+
overridePaths: options.overridePaths,
|
|
1653
|
+
overrides: options.overrides,
|
|
1654
|
+
template: 'commit',
|
|
1655
|
+
content: [
|
|
1656
|
+
...options.userDirection ? [
|
|
1657
|
+
{
|
|
1658
|
+
content: options.userDirection,
|
|
1659
|
+
title: 'User Direction',
|
|
1660
|
+
weight: 1.0
|
|
1661
|
+
}
|
|
1662
|
+
] : [],
|
|
1663
|
+
{
|
|
1664
|
+
content: diffContent,
|
|
1665
|
+
title: 'Diff',
|
|
1666
|
+
weight: 0.5
|
|
1667
|
+
}
|
|
1668
|
+
],
|
|
1669
|
+
context: [
|
|
1670
|
+
...options.context ? [
|
|
1671
|
+
{
|
|
1672
|
+
content: options.context,
|
|
1673
|
+
title: 'User Context',
|
|
1674
|
+
weight: 1.0
|
|
1675
|
+
}
|
|
1676
|
+
] : [],
|
|
1677
|
+
...options.directories ? [
|
|
1678
|
+
{
|
|
1679
|
+
directories: options.directories,
|
|
1680
|
+
weight: 0.5
|
|
1681
|
+
}
|
|
1682
|
+
] : []
|
|
1683
|
+
]
|
|
1684
|
+
});
|
|
1685
|
+
},
|
|
1686
|
+
/**
|
|
1687
|
+
* Create a release prompt with minimal configuration
|
|
1688
|
+
*/ release: async (logContent, diffContent, options)=>{
|
|
1689
|
+
return cook({
|
|
1690
|
+
basePath: options.basePath,
|
|
1691
|
+
overridePaths: options.overridePaths,
|
|
1692
|
+
overrides: options.overrides,
|
|
1693
|
+
template: 'release',
|
|
1694
|
+
content: [
|
|
1695
|
+
...options.releaseFocus ? [
|
|
1696
|
+
{
|
|
1697
|
+
content: options.releaseFocus,
|
|
1698
|
+
title: 'Release Focus',
|
|
1699
|
+
weight: 1.0
|
|
1700
|
+
}
|
|
1701
|
+
] : [],
|
|
1702
|
+
{
|
|
1703
|
+
content: logContent,
|
|
1704
|
+
title: 'Log',
|
|
1705
|
+
weight: 0.5
|
|
1706
|
+
},
|
|
1707
|
+
{
|
|
1708
|
+
content: diffContent,
|
|
1709
|
+
title: 'Diff',
|
|
1710
|
+
weight: 0.5
|
|
1711
|
+
}
|
|
1712
|
+
],
|
|
1713
|
+
context: [
|
|
1714
|
+
...options.context ? [
|
|
1715
|
+
{
|
|
1716
|
+
content: options.context,
|
|
1717
|
+
title: 'User Context',
|
|
1718
|
+
weight: 1.0
|
|
1719
|
+
}
|
|
1720
|
+
] : [],
|
|
1721
|
+
...options.directories ? [
|
|
1722
|
+
{
|
|
1723
|
+
directories: options.directories,
|
|
1724
|
+
weight: 0.5
|
|
1725
|
+
}
|
|
1726
|
+
] : []
|
|
1727
|
+
]
|
|
1728
|
+
});
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
// ===== FLUENT RECIPE BUILDER =====
|
|
1732
|
+
const recipe = (basePath)=>({
|
|
1733
|
+
template: (name)=>({
|
|
1734
|
+
with: (config)=>cook({
|
|
1735
|
+
basePath,
|
|
1736
|
+
template: name,
|
|
1737
|
+
...config
|
|
1738
|
+
})
|
|
1739
|
+
}),
|
|
1740
|
+
persona: (persona)=>({
|
|
1741
|
+
instructions: (...instructions)=>({
|
|
1742
|
+
content: (...content)=>({
|
|
1743
|
+
context: (...context)=>({
|
|
1744
|
+
cook: ()=>cook({
|
|
1745
|
+
basePath,
|
|
1746
|
+
persona,
|
|
1747
|
+
instructions,
|
|
1748
|
+
content,
|
|
1749
|
+
context
|
|
1750
|
+
})
|
|
1751
|
+
}),
|
|
1752
|
+
cook: ()=>cook({
|
|
1753
|
+
basePath,
|
|
1754
|
+
persona,
|
|
1755
|
+
instructions,
|
|
1756
|
+
content
|
|
1757
|
+
})
|
|
1758
|
+
}),
|
|
1759
|
+
cook: ()=>cook({
|
|
1760
|
+
basePath,
|
|
1761
|
+
persona,
|
|
1762
|
+
instructions
|
|
1763
|
+
})
|
|
1764
|
+
}),
|
|
1765
|
+
cook: ()=>cook({
|
|
1766
|
+
basePath,
|
|
1767
|
+
persona
|
|
1768
|
+
})
|
|
1769
|
+
}),
|
|
1770
|
+
cook: (config)=>cook({
|
|
1771
|
+
basePath,
|
|
1772
|
+
...config
|
|
1773
|
+
})
|
|
1774
|
+
});
|
|
1775
|
+
|
|
1776
|
+
const recipes = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
1777
|
+
__proto__: null,
|
|
1778
|
+
commit,
|
|
1779
|
+
configureTemplates,
|
|
1780
|
+
cook,
|
|
1781
|
+
documentation,
|
|
1782
|
+
getTemplates,
|
|
1783
|
+
quick,
|
|
1784
|
+
recipe,
|
|
1785
|
+
release,
|
|
1786
|
+
review
|
|
1787
|
+
}, Symbol.toStringTag, { value: 'Module' }));
|
|
1788
|
+
|
|
1345
1789
|
exports.Builder = builder;
|
|
1346
1790
|
exports.Chat = chat;
|
|
1347
1791
|
exports.Formatter = formatter;
|
|
1348
1792
|
exports.Loader = loader;
|
|
1349
1793
|
exports.Override = override;
|
|
1350
1794
|
exports.Parser = parser;
|
|
1351
|
-
exports.
|
|
1352
|
-
exports.
|
|
1353
|
-
exports.
|
|
1354
|
-
exports.
|
|
1355
|
-
exports.
|
|
1356
|
-
exports.
|
|
1357
|
-
exports.
|
|
1358
|
-
exports.
|
|
1795
|
+
exports.Recipes = recipes;
|
|
1796
|
+
exports.commit = commit;
|
|
1797
|
+
exports.configureTemplates = configureTemplates;
|
|
1798
|
+
exports.cook = cook;
|
|
1799
|
+
exports.createContent = create$b;
|
|
1800
|
+
exports.createContext = create$a;
|
|
1801
|
+
exports.createInstruction = create$9;
|
|
1802
|
+
exports.createParameters = create$d;
|
|
1803
|
+
exports.createPrompt = create$6;
|
|
1804
|
+
exports.createSection = create$8;
|
|
1805
|
+
exports.createTrait = create$7;
|
|
1806
|
+
exports.createWeighted = create$c;
|
|
1807
|
+
exports.documentation = documentation;
|
|
1808
|
+
exports.getTemplates = getTemplates;
|
|
1809
|
+
exports.quick = quick;
|
|
1810
|
+
exports.recipe = recipe;
|
|
1811
|
+
exports.release = release;
|
|
1812
|
+
exports.review = review;
|
|
1359
1813
|
//# sourceMappingURL=riotprompt.cjs.map
|