@riotprompt/riotprompt 0.0.2 → 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.
Files changed (48) hide show
  1. package/README.md +54 -470
  2. package/dist/builder.d.ts +3 -3
  3. package/dist/builder.js +7 -2
  4. package/dist/builder.js.map +1 -1
  5. package/dist/chat.js.map +1 -1
  6. package/dist/constants.js.map +1 -1
  7. package/dist/formatter.js.map +1 -1
  8. package/dist/items/content.js.map +1 -1
  9. package/dist/items/context.js.map +1 -1
  10. package/dist/items/instruction.js.map +1 -1
  11. package/dist/items/parameters.js.map +1 -1
  12. package/dist/items/section.js.map +1 -1
  13. package/dist/items/trait.js.map +1 -1
  14. package/dist/items/weighted.js.map +1 -1
  15. package/dist/loader.js +1 -0
  16. package/dist/loader.js.map +1 -1
  17. package/dist/logger.js.map +1 -1
  18. package/dist/override.d.ts +5 -5
  19. package/dist/override.js +47 -30
  20. package/dist/override.js.map +1 -1
  21. package/dist/parse/markdown.js.map +1 -1
  22. package/dist/parse/text.js.map +1 -1
  23. package/dist/parser.js.map +1 -1
  24. package/dist/prompt.js.map +1 -1
  25. package/dist/recipes.d.ts +405 -0
  26. package/dist/recipes.js +424 -0
  27. package/dist/recipes.js.map +1 -0
  28. package/dist/riotprompt.cjs +484 -32
  29. package/dist/riotprompt.cjs.map +1 -1
  30. package/dist/riotprompt.d.ts +3 -0
  31. package/dist/riotprompt.js +3 -0
  32. package/dist/riotprompt.js.map +1 -1
  33. package/dist/util/general.js.map +1 -1
  34. package/dist/util/markdown.js.map +1 -1
  35. package/dist/util/storage.js.map +1 -1
  36. package/dist/util/text.js.map +1 -1
  37. package/package.json +29 -24
  38. package/.gitcarve/config.yaml +0 -10
  39. package/.gitcarve/context/content.md +0 -11
  40. package/.markdown-doctest-setup.mjs +0 -23
  41. package/.nvmrc +0 -1
  42. package/docs/loader.md +0 -237
  43. package/docs/override.md +0 -323
  44. package/docs/parser.md +0 -130
  45. package/eslint.config.mjs +0 -82
  46. package/nodemon.json +0 -14
  47. package/vite.config.ts +0 -114
  48. package/vitest.config.ts +0 -25
@@ -1111,7 +1111,9 @@ const loader = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1111
1111
 
1112
1112
  const OptionsSchema = zod.z.object({
1113
1113
  logger: zod.z.any().optional().default(DEFAULT_LOGGER),
1114
- configDir: zod.z.string().default('./overrides'),
1114
+ configDirs: zod.z.array(zod.z.string()).default([
1115
+ './overrides'
1116
+ ]),
1115
1117
  overrides: zod.z.boolean().default(false),
1116
1118
  parameters: ParametersSchema.optional().default({})
1117
1119
  });
@@ -1134,42 +1136,54 @@ const create$1 = (overrideOptions = {})=>{
1134
1136
  };
1135
1137
  const override = async (overrideFile, section, sectionOptions = {})=>{
1136
1138
  const currentSectionOptions = loadOptions(sectionOptions);
1137
- const baseFile = path.join(options.configDir, overrideFile);
1138
- const preFile = baseFile.replace('.md', '-pre.md');
1139
- const postFile = baseFile.replace('.md', '-post.md');
1140
- const response = {};
1141
- if (await storage.exists(preFile)) {
1142
- logger.silly('Found pre file %s', preFile);
1143
- const parser$1 = create$4({
1144
- logger
1145
- });
1146
- response.prepend = await parser$1.parseFile(preFile, currentSectionOptions);
1147
- }
1148
- if (await storage.exists(postFile)) {
1149
- logger.silly('Found post file %s', postFile);
1150
- const parser$1 = create$4({
1151
- logger
1152
- });
1153
- response.append = await parser$1.parseFile(postFile, currentSectionOptions);
1154
- }
1155
- if (await storage.exists(baseFile)) {
1156
- logger.silly('Found base file %s', baseFile);
1157
- if (options.overrides) {
1158
- logger.warn('WARNING: Core directives are being overwritten by custom configuration');
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);
1159
1152
  const parser$1 = create$4({
1160
1153
  logger
1161
1154
  });
1162
- response.override = await parser$1.parseFile(baseFile, currentSectionOptions);
1163
- } else {
1164
- logger.error('ERROR: Core directives are being overwritten by custom configuration');
1165
- throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
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
+ }
1166
1180
  }
1167
1181
  }
1168
1182
  return response;
1169
1183
  };
1170
1184
  const customize = async (overrideFile, section, sectionOptions = {})=>{
1171
1185
  const currentSectionOptions = loadOptions(sectionOptions);
1172
- const { overrideContent, prepend, append } = await override(overrideFile, section, currentSectionOptions);
1186
+ const { override: overrideContent, prepends, appends } = await override(overrideFile, section, currentSectionOptions);
1173
1187
  let finalSection = section;
1174
1188
  if (overrideContent) {
1175
1189
  if (options.overrides) {
@@ -1180,11 +1194,13 @@ const create$1 = (overrideOptions = {})=>{
1180
1194
  throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
1181
1195
  }
1182
1196
  }
1183
- if (prepend) {
1197
+ // Apply prepends in order (closest layer first)
1198
+ for (const prepend of prepends){
1184
1199
  logger.silly('Prepend found, adding to content from file %s', prepend);
1185
1200
  finalSection = finalSection.prepend(prepend);
1186
1201
  }
1187
- if (append) {
1202
+ // Apply appends in reverse order (furthest layers first, then closest)
1203
+ for (const append of appends.reverse()){
1188
1204
  logger.silly('Append found, adding to content from file %s', append);
1189
1205
  finalSection = finalSection.append(append);
1190
1206
  }
@@ -1208,7 +1224,9 @@ const override = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1208
1224
  const OptionSchema = zod.z.object({
1209
1225
  logger: zod.z.any().optional().default(DEFAULT_LOGGER),
1210
1226
  basePath: zod.z.string(),
1211
- overridePath: zod.z.string().optional().default("./"),
1227
+ overridePaths: zod.z.array(zod.z.string()).optional().default([
1228
+ "./"
1229
+ ]),
1212
1230
  overrides: zod.z.boolean().optional().default(false),
1213
1231
  parameters: ParametersSchema.optional().default({})
1214
1232
  });
@@ -1220,7 +1238,9 @@ const create = (builderOptions)=>{
1220
1238
  });
1221
1239
  const override$1 = create$1({
1222
1240
  logger,
1223
- configDir: options.overridePath || "./",
1241
+ configDirs: options.overridePaths || [
1242
+ "./"
1243
+ ],
1224
1244
  overrides: options.overrides || false
1225
1245
  });
1226
1246
  const loader$1 = create$2({
@@ -1344,12 +1364,438 @@ const builder = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1344
1364
  create
1345
1365
  }, Symbol.toStringTag, { value: 'Module' }));
1346
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
+
1347
1789
  exports.Builder = builder;
1348
1790
  exports.Chat = chat;
1349
1791
  exports.Formatter = formatter;
1350
1792
  exports.Loader = loader;
1351
1793
  exports.Override = override;
1352
1794
  exports.Parser = parser;
1795
+ exports.Recipes = recipes;
1796
+ exports.commit = commit;
1797
+ exports.configureTemplates = configureTemplates;
1798
+ exports.cook = cook;
1353
1799
  exports.createContent = create$b;
1354
1800
  exports.createContext = create$a;
1355
1801
  exports.createInstruction = create$9;
@@ -1358,4 +1804,10 @@ exports.createPrompt = create$6;
1358
1804
  exports.createSection = create$8;
1359
1805
  exports.createTrait = create$7;
1360
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;
1361
1813
  //# sourceMappingURL=riotprompt.cjs.map