@riotprompt/riotprompt 0.0.3 → 0.0.6

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.
@@ -5,7 +5,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
5
  const zod = require('zod');
6
6
  const fs = require('fs/promises');
7
7
  const path = require('path');
8
- const marked = require('marked');
9
8
  const fs$1 = require('fs');
10
9
  const glob = require('glob');
11
10
  const crypto = require('crypto');
@@ -202,6 +201,16 @@ const create$8 = (options = {})=>{
202
201
  };
203
202
  return append(item, itemOptions);
204
203
  };
204
+ const toJSON = ()=>{
205
+ return {
206
+ title: section.title,
207
+ items: items.map((item)=>{
208
+ // If the item has a toJSON method, call it, otherwise return the item itself
209
+ return typeof item === 'object' && item !== null && 'toJSON' in item && typeof item.toJSON === 'function' ? item.toJSON() : item;
210
+ }),
211
+ weight: section.weight
212
+ };
213
+ };
205
214
  const section = {
206
215
  title: sectionOptions.title,
207
216
  items,
@@ -211,7 +220,8 @@ const create$8 = (options = {})=>{
211
220
  prepend,
212
221
  insert,
213
222
  remove,
214
- replace
223
+ replace,
224
+ toJSON
215
225
  };
216
226
  return section;
217
227
  };
@@ -495,7 +505,9 @@ const formatter = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty(
495
505
  create: create$5
496
506
  }, Symbol.toStringTag, { value: 'Module' }));
497
507
 
498
- const parseMarkdown = (input, options = {})=>{
508
+ const parseMarkdown = async (input, options = {})=>{
509
+ // Dynamic import for marked (ES module)
510
+ const { marked } = await import('marked');
499
511
  let markdownContent;
500
512
  if (typeof input === 'string') {
501
513
  markdownContent = input;
@@ -504,7 +516,7 @@ const parseMarkdown = (input, options = {})=>{
504
516
  }
505
517
  const sectionOptions = SectionOptionsSchema.parse(options);
506
518
  // Use marked.lexer to get tokens without full parsing/rendering
507
- const tokens = marked.marked.lexer(markdownContent);
519
+ const tokens = marked.lexer(markdownContent);
508
520
  // Create the main section (with a Title from the options)
509
521
  const mainSection = create$8(sectionOptions);
510
522
  // Track sections at each depth level
@@ -788,7 +800,7 @@ const create$4 = (parserOptions)=>{
788
800
  const content = await fs__namespace.readFile(filePath, 'utf-8');
789
801
  // Only use the filename as title if no title was explicitly provided
790
802
  const fileName = path__namespace.basename(filePath, path__namespace.extname(filePath));
791
- return parse(content, {
803
+ return await parse(content, {
792
804
  ...currentOptions,
793
805
  title: (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.title) || fileName
794
806
  });
@@ -808,11 +820,11 @@ const create$4 = (parserOptions)=>{
808
820
  *
809
821
  * @param content The content to parse
810
822
  * @returns A Section containing all content in a hierarchical structure
811
- */ const parse = (content, options = {})=>{
823
+ */ const parse = async (content, options = {})=>{
812
824
  const currentOptions = loadOptions(options);
813
825
  let mainSection;
814
826
  if (isMarkdown(content)) {
815
- mainSection = parseMarkdown(content, currentOptions);
827
+ mainSection = await parseMarkdown(content, currentOptions);
816
828
  } else if (isText(content)) {
817
829
  mainSection = parseText(content, currentOptions);
818
830
  } else {
@@ -1332,7 +1344,7 @@ const create = (builderOptions)=>{
1332
1344
  const addContent = async (content, sectionOptions = {})=>{
1333
1345
  logger.debug("Adding content", typeof content);
1334
1346
  const currentOptions = loadOptions(sectionOptions);
1335
- const parsedContentSection = parser$1.parse(content, currentOptions);
1347
+ const parsedContentSection = await parser$1.parse(content, currentOptions);
1336
1348
  contentSection.add(parsedContentSection);
1337
1349
  return instance;
1338
1350
  };
@@ -1340,7 +1352,7 @@ const create = (builderOptions)=>{
1340
1352
  const addContext = async (context, sectionOptions = {})=>{
1341
1353
  logger.debug("Adding context", typeof context);
1342
1354
  const currentOptions = loadOptions(sectionOptions);
1343
- const parsedContextSection = parser$1.parse(context, currentOptions);
1355
+ const parsedContextSection = await parser$1.parse(context, currentOptions);
1344
1356
  contextSection.add(parsedContextSection);
1345
1357
  return instance;
1346
1358
  };
@@ -1392,104 +1404,50 @@ const RecipeConfigSchema = zod.z.object({
1392
1404
  ]),
1393
1405
  overrides: zod.z.boolean().optional().default(false),
1394
1406
  parameters: ParametersSchema.optional().default({}),
1395
- // Content sections - smart inference based on naming
1407
+ // Content sections
1396
1408
  persona: ContentItemSchema.optional(),
1397
1409
  instructions: zod.z.array(ContentItemSchema).optional().default([]),
1398
1410
  content: zod.z.array(ContentItemSchema).optional().default([]),
1399
1411
  context: zod.z.array(ContentItemSchema).optional().default([]),
1400
1412
  // Templates and inheritance
1401
1413
  extends: zod.z.string().optional(),
1402
- template: zod.z.enum([
1403
- 'commit',
1404
- 'release',
1405
- 'documentation',
1406
- 'review',
1407
- 'custom'
1408
- ]).optional()
1414
+ template: zod.z.string().optional()
1409
1415
  });
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
1416
  // User-customizable template registry
1462
- let TEMPLATES = {
1463
- ...DEFAULT_TEMPLATES
1464
- };
1417
+ let TEMPLATES = {};
1465
1418
  /**
1466
- * Configure custom template paths (perfect for KodrDriv constants!)
1419
+ * Register custom templates with the recipes system
1467
1420
  *
1468
1421
  * @example
1469
1422
  * ```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 }]
1423
+ * // Register your own templates
1424
+ * registerTemplates({
1425
+ * myWorkflow: {
1426
+ * persona: { path: "personas/my-persona.md" },
1427
+ * instructions: [{ path: "instructions/my-instructions.md" }]
1475
1428
  * },
1476
- * release: {
1477
- * persona: { path: DEFAULT_PERSONA_RELEASER_FILE },
1478
- * instructions: [{ path: DEFAULT_INSTRUCTIONS_RELEASE_FILE }]
1429
+ * anotherTemplate: {
1430
+ * persona: { content: "You are a helpful assistant" },
1431
+ * instructions: [{ content: "Follow these steps..." }]
1479
1432
  * }
1480
1433
  * });
1481
1434
  * ```
1482
- */ const configureTemplates = (customTemplates)=>{
1435
+ */ const registerTemplates = (templates)=>{
1483
1436
  TEMPLATES = {
1484
- ...DEFAULT_TEMPLATES,
1485
- ...customTemplates
1437
+ ...TEMPLATES,
1438
+ ...templates
1486
1439
  };
1487
1440
  };
1488
1441
  /**
1489
- * Get current template configuration
1442
+ * Get currently registered templates
1490
1443
  */ const getTemplates = ()=>({
1491
1444
  ...TEMPLATES
1492
1445
  });
1446
+ /**
1447
+ * Clear all registered templates
1448
+ */ const clearTemplates = ()=>{
1449
+ TEMPLATES = {};
1450
+ };
1493
1451
  // ===== CORE RECIPE ENGINE =====
1494
1452
  const cook = async (config)=>{
1495
1453
  // Parse and validate configuration with defaults
@@ -1512,8 +1470,20 @@ const cook = async (config)=>{
1512
1470
  const template = TEMPLATES[validatedConfig.template];
1513
1471
  if (template) {
1514
1472
  finalConfig = {
1515
- ...template,
1516
- ...validatedConfig
1473
+ ...validatedConfig,
1474
+ persona: validatedConfig.persona || template.persona,
1475
+ instructions: [
1476
+ ...template.instructions || [],
1477
+ ...validatedConfig.instructions || []
1478
+ ],
1479
+ content: [
1480
+ ...template.content || [],
1481
+ ...validatedConfig.content || []
1482
+ ],
1483
+ context: [
1484
+ ...template.context || [],
1485
+ ...validatedConfig.context || []
1486
+ ]
1517
1487
  };
1518
1488
  }
1519
1489
  }
@@ -1564,7 +1534,10 @@ const cook = async (config)=>{
1564
1534
  parameters: finalConfig.parameters});
1565
1535
  }
1566
1536
  // Process content
1537
+ // eslint-disable-next-line no-console
1567
1538
  for (const item of finalConfig.content || []){
1539
+ // eslint-disable-next-line no-console
1540
+ console.log('Processing content item:', JSON.stringify(item, null, 2));
1568
1541
  await processContentItem(item, contentSection, 'content', {
1569
1542
  basePath: finalConfig.basePath,
1570
1543
  parser: parser$1,
@@ -1595,11 +1568,11 @@ const processContentItem = async (item, section, type, ctx)=>{
1595
1568
  };
1596
1569
  if (typeof item === 'string') {
1597
1570
  // Simple string content
1598
- const parsedSection = ctx.parser.parse(item, sectionOptions);
1571
+ const parsedSection = await ctx.parser.parse(item, sectionOptions);
1599
1572
  section.add(parsedSection);
1600
1573
  } else if ('content' in item) {
1601
1574
  // Inline content with options
1602
- const parsedSection = ctx.parser.parse(item.content, {
1575
+ const parsedSection = await ctx.parser.parse(item.content, {
1603
1576
  ...sectionOptions,
1604
1577
  title: item.title,
1605
1578
  weight: item.weight
@@ -1625,165 +1598,72 @@ const processContentItem = async (item, section, type, ctx)=>{
1625
1598
  section.add(sections);
1626
1599
  }
1627
1600
  };
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
1601
  // ===== 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
- });
1602
+ const recipe = (basePath)=>{
1603
+ const config = {
1604
+ basePath
1605
+ };
1606
+ const builder = {
1607
+ template: (name)=>{
1608
+ config.template = name;
1609
+ return builder;
1610
+ },
1611
+ with: (partialConfig)=>{
1612
+ Object.assign(config, partialConfig);
1613
+ return builder;
1614
+ },
1615
+ persona: (persona)=>{
1616
+ config.persona = persona;
1617
+ return builder;
1618
+ },
1619
+ instructions: (...instructions)=>{
1620
+ config.instructions = [
1621
+ ...config.instructions || [],
1622
+ ...instructions
1623
+ ];
1624
+ return builder;
1625
+ },
1626
+ content: (...content)=>{
1627
+ config.content = [
1628
+ ...config.content || [],
1629
+ ...content
1630
+ ];
1631
+ return builder;
1632
+ },
1633
+ context: (...context)=>{
1634
+ config.context = [
1635
+ ...config.context || [],
1636
+ ...context
1637
+ ];
1638
+ return builder;
1639
+ },
1640
+ parameters: (parameters)=>{
1641
+ config.parameters = {
1642
+ ...config.parameters,
1643
+ ...parameters
1644
+ };
1645
+ return builder;
1646
+ },
1647
+ overrides: (enabled)=>{
1648
+ config.overrides = enabled;
1649
+ return builder;
1650
+ },
1651
+ overridePaths: (paths)=>{
1652
+ config.overridePaths = paths;
1653
+ return builder;
1654
+ },
1655
+ cook: ()=>cook(config)
1656
+ };
1657
+ return builder;
1658
+ };
1775
1659
 
1776
1660
  const recipes = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1777
1661
  __proto__: null,
1778
- commit,
1779
- configureTemplates,
1662
+ clearTemplates,
1780
1663
  cook,
1781
- documentation,
1782
1664
  getTemplates,
1783
- quick,
1784
1665
  recipe,
1785
- release,
1786
- review
1666
+ registerTemplates
1787
1667
  }, Symbol.toStringTag, { value: 'Module' }));
1788
1668
 
1789
1669
  exports.Builder = builder;
@@ -1793,8 +1673,7 @@ exports.Loader = loader;
1793
1673
  exports.Override = override;
1794
1674
  exports.Parser = parser;
1795
1675
  exports.Recipes = recipes;
1796
- exports.commit = commit;
1797
- exports.configureTemplates = configureTemplates;
1676
+ exports.clearTemplates = clearTemplates;
1798
1677
  exports.cook = cook;
1799
1678
  exports.createContent = create$b;
1800
1679
  exports.createContext = create$a;
@@ -1804,10 +1683,7 @@ exports.createPrompt = create$6;
1804
1683
  exports.createSection = create$8;
1805
1684
  exports.createTrait = create$7;
1806
1685
  exports.createWeighted = create$c;
1807
- exports.documentation = documentation;
1808
1686
  exports.getTemplates = getTemplates;
1809
- exports.quick = quick;
1810
1687
  exports.recipe = recipe;
1811
- exports.release = release;
1812
- exports.review = review;
1688
+ exports.registerTemplates = registerTemplates;
1813
1689
  //# sourceMappingURL=riotprompt.cjs.map