$npx -y skills add adityahimaone/hermes-agent-rtk-caveman --skill caveman-rtk-integrationIntegrates Caveman templating engine with RTK (Rust Token Killer) for token-optimized output formatting. Provides a wrapper script and patterns for using Caveman templates to compress CLI output.
| 1 | # Caveman + RTK Integration Skill |
| 2 | |
| 3 | This skill provides a reusable approach for integrating the Caveman JS templating engine with RTK to minimize token output when formatting CLI command results. |
| 4 | |
| 5 | ## Overview |
| 6 | When working with CLI tools that produce verbose output, combining Caveman templating with RTK can reduce token usage by 60-90% by: |
| 7 | 1. Using RTK to minimize noise from CLI commands |
| 8 | 2. Using Caveman templates to define output structure once |
| 9 | 3. Only transmitting the variable data between runs |
| 10 | |
| 11 | ## Installation & Setup |
| 12 | |
| 13 | ### 1. Install Caveman globally |
| 14 | ```bash |
| 15 | npm install -g caveman |
| 16 | ``` |
| 17 | |
| 18 | ### 2. Create Caveman wrapper script |
| 19 | Create `~/bin/caveman` with the following content: |
| 20 | |
| 21 | ```bash |
| 22 | #!/usr/bin/env node |
| 23 | const caveman = require("/opt/homebrew/lib/node_modules/caveman/caveman.js"); |
| 24 | const fs = require("fs"); |
| 25 | const path = require("path"); |
| 26 | |
| 27 | const args = process.argv.slice(2); |
| 28 | if (args.length === 0) { |
| 29 | console.error("Usage: caveman <template> [data.json]"); |
| 30 | process.exit(1); |
| 31 | } |
| 32 | |
| 33 | const templatePath = args[0]; |
| 34 | let data = {}; |
| 35 | |
| 36 | if (args.length > 1) { |
| 37 | const dataPath = args[1]; |
| 38 | data = JSON.parse(fs.readFileSync(dataPath, "utf8")); |
| 39 | } |
| 40 | |
| 41 | // Read template file |
| 42 | const template = fs.readFileSync(templatePath, "utf8"); |
| 43 | |
| 44 | // Generate a template name from the file path (without extension) |
| 45 | const templateName = path.basename(templatePath, path.extname(templatePath)); |
| 46 | |
| 47 | // Register the template |
| 48 | caveman.register(templateName, template); |
| 49 | |
| 50 | // Render with data and trim output |
| 51 | const result = caveman.render(templateName, data).trim(); |
| 52 | console.log(result); |
| 53 | ``` |
| 54 | |
| 55 | Make it executable: |
| 56 | ```bash |
| 57 | chmod +x ~/bin/caveman |
| 58 | ``` |
| 59 | |
| 60 | ### 3. Ensure RTK is installed |
| 61 | ```bash |
| 62 | # Should already be available if following RTK instructions |
| 63 | rtk gain # Verify RTK is working |
| 64 | ``` |
| 65 | |
| 66 | ### Caveman Template Syntax Reference |
| 67 | |
| 68 | Based on the Caveman documentation and practical usage, here are the key syntax elements: |
| 69 | |
| 70 | ### Basic Variable Output |
| 71 | ``` |
| 72 | Hello {{d.name}}! // Outputs the 'name' property from data object |
| 73 | ``` |
| 74 | |
| 75 | ### Loops (for arrays) |
| 76 | ``` |
| 77 | {{- for d.items as item }} |
| 78 | - {{item}} |
| 79 | {{- end }} |
| 80 | ``` |
| 81 | |
| 82 | ### Loops (for objects/arrays with key access) |
| 83 | ``` |
| 84 | {{- each d.object as attribute }} |
| 85 | {{_key}}: {{attribute}} |
| 86 | {{- end }} |
| 87 | ``` |
| 88 | |
| 89 | ### Conditionals |
| 90 | ``` |
| 91 | {{- if d.showDetails }} |
| 92 | Details: {{d.details}} |
| 93 | {{- end }} |
| 94 | ``` |
| 95 | |
| 96 | ### Loop Control Variables (available in both `for` and `each` loops) |
| 97 | - `_i` = current index (zero-based) |
| 98 | - `_len` = total length of array/object |
| 99 | - `_key` = current key (in each loops) |
| 100 | - `@last` = true if current iteration is the last item |
| 101 | |
| 102 | ### Conditional Loop Suffix (for separators) |
| 103 | Use `{{- unless @last }}, {{/unless}}` inside loops to add separators between items but not after the last item. |
| 104 | |
| 105 | ### Escaping & Macros |
| 106 | Caveman supports custom macros and escaping, but for basic token optimization, the above is sufficient. |
| 107 | |
| 108 | ## Usage Pattern for Token Optimization |
| 109 | |
| 110 | ### Step 1: Create a Template File |
| 111 | Define your output structure once in a template file (e.g., `gitstatus_template.txt`): |
| 112 | ``` |
| 113 | {{- for d.staged as file }} |
| 114 | + {{file}} |
| 115 | {{- end }} |
| 116 | {{- for d.modified as file }} |
| 117 | ~ {{file}} |
| 118 | {{- end }} |
| 119 | ``` |
| 120 | |
| 121 | ### Step 2: Prepare Data JSON |
| 122 | Create a JSON file with just the variable data (e.g., `gitstatus_data.json`): |
| 123 | ```json |
| 124 | { |
| 125 | "staged": ["src/components/Button.js", "src/styles/tailwind.css"], |
| 126 | "modified": ["src/pages/index.js", "src/utils/helpers.ts"] |
| 127 | } |
| 128 | ``` |
| 129 | |
| 130 | ### Step 3: Generate Output with RTK + Caveman |
| 131 | ```bash |
| 132 | # Use RTK to minimize command noise, then Caveman to format |
| 133 | rtk ~/bin/caveman gitstatus_template.txt gitstatus_data.json |
| 134 | ``` |
| 135 | |
| 136 | ### Output: |
| 137 | ``` |
| 138 | + src/components/Button.js |
| 139 | + src/styles/tailwind.css |
| 140 | ~ src/pages/index.js |
| 141 | ~ src/utils/helpers.ts |
| 142 | ``` |
| 143 | |
| 144 | ## Integration with Market Alpha Scout |
| 145 | |
| 146 | The Market Alpha Scout skill uses this pattern to: |
| 147 | 1. Scrape data from Stockbro.id using Firecrawl |
| 148 | 2. Search for KOL recommendations via Google site-specific searches |
| 149 | 3. Format results using a Caveman template |
| 150 | 4. Apply RTK to minimize token output from all CLI commands |
| 151 | |
| 152 | ### Example Caveman Template for Stock Output: |
| 153 | ```\n[ROCKET] Daily Stockpick Radar - {{d.date}}\nKode Saham | Sumber | Strategi | Target Price / ARA | Stop Loss\n-----------|--------|----------|-------------------|----------\n{{- for d.stocks as stock }}\n {{stock.code}} | {{stock.source}} | {{stock.strategy}} | {{stock.target}} | {{stock.stop_loss}}\n{{- end }}\n\n{{- if d.high_conviction }}\n*High Conviction Setup: {{- each d.high_conviction as conviction }}{{conviction}}{{- unless @last }}, {{/unless}}{{- end }}*\n{{- end }}\n*Risk Warning: Investasi saham memiliki risiko tinggi. Lakukan DYOR (Do Your Own Research) sebelum membuat keputusan investasi.*\n``` |
| 154 | |
| 155 | ### Practical Example: Daily Stock Report |
| 156 | Based on real usage, here's a working example for generating daily s |