@rune-kit/rune 2.1.1 → 2.2.1

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 (157) hide show
  1. package/README.md +40 -34
  2. package/compiler/__tests__/pack-split.test.js +145 -0
  3. package/compiler/adapters/antigravity.js +1 -1
  4. package/compiler/adapters/codex.js +77 -0
  5. package/compiler/adapters/cursor.js +1 -1
  6. package/compiler/adapters/generic.js +1 -1
  7. package/compiler/adapters/index.js +4 -0
  8. package/compiler/adapters/opencode.js +86 -0
  9. package/compiler/adapters/windsurf.js +1 -1
  10. package/compiler/bin/rune.js +10 -7
  11. package/compiler/doctor.js +42 -0
  12. package/compiler/emitter.js +64 -10
  13. package/compiler/parser.js +42 -3
  14. package/compiler/transformer.js +10 -6
  15. package/compiler/transforms/branding.js +1 -1
  16. package/compiler/transforms/compliance.js +40 -0
  17. package/extensions/ai-ml/PACK.md +38 -474
  18. package/extensions/ai-ml/skills/ai-agents.md +172 -0
  19. package/extensions/ai-ml/skills/code-sandbox.md +187 -0
  20. package/extensions/ai-ml/skills/deep-research.md +146 -0
  21. package/extensions/ai-ml/skills/embedding-search.md +66 -0
  22. package/extensions/ai-ml/skills/fine-tuning-guide.md +74 -0
  23. package/extensions/ai-ml/skills/llm-architect.md +125 -0
  24. package/extensions/ai-ml/skills/llm-integration.md +64 -0
  25. package/extensions/ai-ml/skills/prompt-patterns.md +72 -0
  26. package/extensions/ai-ml/skills/rag-patterns.md +66 -0
  27. package/extensions/ai-ml/skills/web-extraction.md +114 -0
  28. package/extensions/analytics/PACK.md +19 -484
  29. package/extensions/analytics/skills/ab-testing.md +72 -0
  30. package/extensions/analytics/skills/dashboard-patterns.md +83 -0
  31. package/extensions/analytics/skills/data-validation.md +68 -0
  32. package/extensions/analytics/skills/funnel-analysis.md +81 -0
  33. package/extensions/analytics/skills/sql-patterns.md +57 -0
  34. package/extensions/analytics/skills/statistical-analysis.md +79 -0
  35. package/extensions/analytics/skills/tracking-setup.md +71 -0
  36. package/extensions/backend/PACK.md +44 -618
  37. package/extensions/backend/skills/api-patterns.md +84 -0
  38. package/extensions/backend/skills/async-pipeline.md +193 -0
  39. package/extensions/backend/skills/auth-patterns.md +97 -0
  40. package/extensions/backend/skills/background-jobs.md +133 -0
  41. package/extensions/backend/skills/caching-patterns.md +108 -0
  42. package/extensions/backend/skills/cli-generation.md +133 -0
  43. package/extensions/backend/skills/database-patterns.md +87 -0
  44. package/extensions/backend/skills/middleware-patterns.md +104 -0
  45. package/extensions/chrome-ext/PACK.md +19 -921
  46. package/extensions/chrome-ext/skills/cws-preflight.md +143 -0
  47. package/extensions/chrome-ext/skills/cws-publish.md +104 -0
  48. package/extensions/chrome-ext/skills/ext-ai-integration.md +251 -0
  49. package/extensions/chrome-ext/skills/ext-messaging.md +139 -0
  50. package/extensions/chrome-ext/skills/ext-storage.md +133 -0
  51. package/extensions/chrome-ext/skills/mv3-scaffold.md +164 -0
  52. package/extensions/content/PACK.md +43 -335
  53. package/extensions/content/skills/blog-patterns.md +88 -0
  54. package/extensions/content/skills/cms-integration.md +131 -0
  55. package/extensions/content/skills/content-scoring.md +107 -0
  56. package/extensions/content/skills/i18n.md +83 -0
  57. package/extensions/content/skills/mdx-authoring.md +137 -0
  58. package/extensions/content/skills/reference.md +1014 -0
  59. package/extensions/content/skills/seo-patterns.md +67 -0
  60. package/extensions/content/skills/video-repurpose.md +153 -0
  61. package/extensions/devops/PACK.md +38 -457
  62. package/extensions/devops/skills/chaos-testing.md +67 -0
  63. package/extensions/devops/skills/ci-cd.md +75 -0
  64. package/extensions/devops/skills/docker.md +58 -0
  65. package/extensions/devops/skills/edge-serverless.md +163 -0
  66. package/extensions/devops/skills/infra-as-code.md +158 -0
  67. package/extensions/devops/skills/kubernetes.md +110 -0
  68. package/extensions/devops/skills/monitoring.md +57 -0
  69. package/extensions/devops/skills/server-setup.md +64 -0
  70. package/extensions/devops/skills/ssl-domain.md +42 -0
  71. package/extensions/ecommerce/PACK.md +62 -226
  72. package/extensions/ecommerce/skills/cart-system.md +79 -0
  73. package/extensions/ecommerce/skills/inventory-mgmt.md +102 -0
  74. package/extensions/ecommerce/skills/order-management.md +126 -0
  75. package/extensions/ecommerce/skills/payment-integration.md +472 -0
  76. package/extensions/ecommerce/skills/shopify-dev.md +69 -0
  77. package/extensions/ecommerce/skills/subscription-billing.md +93 -0
  78. package/extensions/ecommerce/skills/tax-compliance.md +117 -0
  79. package/extensions/gamedev/PACK.md +66 -317
  80. package/extensions/gamedev/skills/asset-pipeline.md +74 -0
  81. package/extensions/gamedev/skills/audio-system.md +129 -0
  82. package/extensions/gamedev/skills/camera-system.md +87 -0
  83. package/extensions/gamedev/skills/ecs.md +98 -0
  84. package/extensions/gamedev/skills/game-loops.md +72 -0
  85. package/extensions/gamedev/skills/input-system.md +199 -0
  86. package/extensions/gamedev/skills/multiplayer.md +180 -0
  87. package/extensions/gamedev/skills/particles.md +105 -0
  88. package/extensions/gamedev/skills/physics-engine.md +89 -0
  89. package/extensions/gamedev/skills/scene-management.md +146 -0
  90. package/extensions/gamedev/skills/threejs-patterns.md +90 -0
  91. package/extensions/gamedev/skills/webgl.md +71 -0
  92. package/extensions/mobile/PACK.md +56 -223
  93. package/extensions/mobile/skills/app-store-connect.md +152 -0
  94. package/extensions/mobile/skills/app-store-prep.md +66 -0
  95. package/extensions/mobile/skills/deep-linking.md +109 -0
  96. package/extensions/mobile/skills/flutter.md +60 -0
  97. package/extensions/mobile/skills/ios-build-pipeline.md +142 -0
  98. package/extensions/mobile/skills/native-bridge.md +66 -0
  99. package/extensions/mobile/skills/ota-updates.md +97 -0
  100. package/extensions/mobile/skills/push-notifications.md +111 -0
  101. package/extensions/mobile/skills/react-native.md +82 -0
  102. package/extensions/saas/PACK.md +26 -720
  103. package/extensions/saas/skills/billing-integration.md +121 -0
  104. package/extensions/saas/skills/feature-flags.md +130 -0
  105. package/extensions/saas/skills/multi-tenant.md +103 -0
  106. package/extensions/saas/skills/onboarding-flow.md +139 -0
  107. package/extensions/saas/skills/subscription-flow.md +95 -0
  108. package/extensions/saas/skills/team-management.md +144 -0
  109. package/extensions/security/PACK.md +10 -448
  110. package/extensions/security/skills/api-security.md +140 -0
  111. package/extensions/security/skills/compliance.md +68 -0
  112. package/extensions/security/skills/owasp-audit.md +64 -0
  113. package/extensions/security/skills/pentest-patterns.md +77 -0
  114. package/extensions/security/skills/secret-mgmt.md +65 -0
  115. package/extensions/security/skills/supply-chain.md +65 -0
  116. package/extensions/trading/PACK.md +18 -535
  117. package/extensions/trading/skills/chart-components.md +55 -0
  118. package/extensions/trading/skills/experiment-loop.md +125 -0
  119. package/extensions/trading/skills/fintech-patterns.md +47 -0
  120. package/extensions/trading/skills/indicator-library.md +58 -0
  121. package/extensions/trading/skills/quant-analysis.md +111 -0
  122. package/extensions/trading/skills/realtime-data.md +58 -0
  123. package/extensions/trading/skills/trade-logic.md +104 -0
  124. package/extensions/ui/PACK.md +34 -853
  125. package/extensions/ui/skills/a11y-audit.md +91 -0
  126. package/extensions/ui/skills/animation-patterns.md +106 -0
  127. package/extensions/ui/skills/component-patterns.md +75 -0
  128. package/extensions/ui/skills/design-decision.md +98 -0
  129. package/extensions/ui/skills/design-system.md +68 -0
  130. package/extensions/ui/skills/landing-patterns.md +155 -0
  131. package/extensions/ui/skills/palette-picker.md +162 -0
  132. package/extensions/ui/skills/react-health.md +90 -0
  133. package/extensions/ui/skills/type-system.md +125 -0
  134. package/extensions/ui/skills/web-vitals.md +153 -0
  135. package/extensions/zalo/PACK.md +117 -0
  136. package/extensions/zalo/skills/zalo-oa-mcp.md +317 -0
  137. package/extensions/zalo/skills/zalo-oa-messaging.md +429 -0
  138. package/extensions/zalo/skills/zalo-oa-setup.md +236 -0
  139. package/extensions/zalo/skills/zalo-oa-webhook.md +189 -0
  140. package/extensions/zalo/skills/zalo-personal-messaging.md +194 -0
  141. package/extensions/zalo/skills/zalo-personal-setup.md +153 -0
  142. package/extensions/zalo/skills/zalo-rate-guard.md +219 -0
  143. package/package.json +5 -2
  144. package/skills/brainstorm/SKILL.md +63 -1
  145. package/skills/cook/SKILL.md +89 -6
  146. package/skills/debug/SKILL.md +5 -0
  147. package/skills/fix/SKILL.md +5 -0
  148. package/skills/mcp-builder/SKILL.md +48 -1
  149. package/skills/neural-memory/SKILL.md +362 -0
  150. package/skills/plan/SKILL.md +3 -0
  151. package/skills/rescue/SKILL.md +5 -0
  152. package/skills/review/SKILL.md +44 -5
  153. package/skills/review-intake/SKILL.md +17 -1
  154. package/skills/skill-router/SKILL.md +106 -8
  155. package/skills/team/SKILL.md +24 -1
  156. package/skills/test/SKILL.md +18 -0
  157. package/skills/verification/SKILL.md +40 -1
@@ -1,19 +1,20 @@
1
1
  ---
2
2
  name: "@rune/ai-ml"
3
- description: AI/ML integration patterns — LLM integration, RAG pipelines, embeddings, and fine-tuning workflows.
3
+ description: AI/ML integration patterns — LLM integration, RAG pipelines, embeddings, fine-tuning workflows, stateful AI agents, code execution sandboxes, web extraction, and deep research loops.
4
4
  metadata:
5
5
  author: runedev
6
- version: "0.2.0"
6
+ version: "0.4.0"
7
7
  layer: L4
8
8
  price: "$15"
9
9
  target: AI engineers
10
+ format: split
10
11
  ---
11
12
 
12
13
  # @rune/ai-ml
13
14
 
14
15
  ## Purpose
15
16
 
16
- AI-powered features fail in predictable ways: LLM calls without retry logic that crash on rate limits, RAG pipelines that retrieve irrelevant chunks because the chunking strategy ignores document structure, embedding search that returns semantic matches with zero keyword overlap, and fine-tuning runs that overfit because the eval set leaked into training data. This pack codifies production patterns for each — from API client resilience to retrieval quality to model evaluation — so AI features ship with the reliability of traditional software.
17
+ AI-powered features fail in predictable ways: LLM calls without retry logic that crash on rate limits, RAG pipelines that retrieve irrelevant chunks because the chunking strategy ignores document structure, embedding search that returns semantic matches with zero keyword overlap, fine-tuning runs that overfit because the eval set leaked into training data, AI agents that leak state across requests or lose progress on crashes, and code interpreters that execute untrusted LLM output without isolation. This pack codifies production patterns for each — from API client resilience to retrieval quality to model evaluation to agent state management to secure sandboxed execution — so AI features ship with the reliability of traditional software.
17
18
 
18
19
  ## Triggers
19
20
 
@@ -22,447 +23,27 @@ AI-powered features fail in predictable ways: LLM calls without retry logic that
22
23
  - `/rune rag-patterns` — build or audit RAG pipeline
23
24
  - `/rune embedding-search` — implement or optimize semantic search
24
25
  - `/rune fine-tuning-guide` — prepare and execute fine-tuning workflow
26
+ - `/rune ai-agents` — design and build stateful AI agents
27
+ - `/rune code-sandbox` — set up secure code execution for AI
28
+ - `/rune web-extraction` — build structured data extraction from web pages
29
+ - `/rune deep-research` — implement iterative AI research loops with convergence
25
30
  - Called by `cook` (L1) when AI/ML task detected
26
31
  - Called by `plan` (L2) when AI architecture decisions needed
27
32
 
28
33
  ## Skills Included
29
34
 
30
- ### llm-integration
31
-
32
- LLM integration patterns API client wrappers, streaming responses, structured output, retry with exponential backoff, model fallback chains, prompt versioning.
33
-
34
- #### Workflow
35
-
36
- **Step 1 Detect LLM usage**
37
- Use Grep to find LLM API calls: `openai.chat`, `anthropic.messages`, `OpenAI(`, `Anthropic(`, `generateText`, `streamText`. Read client initialization and prompt construction to understand: model selection, error handling, output parsing, and token management.
38
-
39
- **Step 2 Audit resilience**
40
- Check for: no retry on rate limit (429), no timeout on API calls, unstructured output parsing (regex on LLM text instead of function calling), hardcoded prompts without versioning, no token counting before request, missing fallback model chain, and streaming without backpressure handling.
41
-
42
- **Step 3 — Emit robust LLM client**
43
- Emit: typed client wrapper with exponential backoff retry, structured output via Zod schema + function calling, streaming with proper error boundaries, token budget management, and prompt version registry.
44
-
45
- #### Example
46
-
47
- ```typescript
48
- // Robust LLM client — retry, structured output, fallback chain
49
- import OpenAI from 'openai';
50
- import { z } from 'zod';
51
-
52
- const client = new OpenAI();
53
-
54
- const SentimentSchema = z.object({
55
- sentiment: z.enum(['positive', 'negative', 'neutral']),
56
- confidence: z.number().min(0).max(1),
57
- reasoning: z.string(),
58
- });
59
-
60
- async function analyzeSentiment(text: string, attempt = 0): Promise<z.infer<typeof SentimentSchema>> {
61
- const models = ['gpt-4o-mini', 'gpt-4o'] as const; // fallback chain
62
- const model = attempt >= 2 ? models[1] : models[0];
63
-
64
- try {
65
- const response = await client.chat.completions.create({
66
- model,
67
- messages: [
68
- { role: 'system', content: 'Analyze sentiment. Return JSON matching the schema.' },
69
- { role: 'user', content: text },
70
- ],
71
- response_format: { type: 'json_object' },
72
- max_tokens: 200,
73
- timeout: 10_000,
74
- });
75
-
76
- return SentimentSchema.parse(JSON.parse(response.choices[0].message.content!));
77
- } catch (err) {
78
- if (err instanceof OpenAI.RateLimitError && attempt < 3) {
79
- await new Promise(r => setTimeout(r, Math.pow(2, attempt) * 1000));
80
- return analyzeSentiment(text, attempt + 1);
81
- }
82
- throw err;
83
- }
84
- }
85
- ```
86
-
87
- ---
88
-
89
- ### rag-patterns
90
-
91
- RAG pipeline patterns — document chunking, embedding generation, vector store setup, retrieval strategies, reranking.
92
-
93
- #### Workflow
94
-
95
- **Step 1 — Detect RAG components**
96
- Use Grep to find vector store usage: `PineconeClient`, `pgvector`, `Weaviate`, `ChromaClient`, `QdrantClient`. Find embedding calls: `embeddings.create`, `embed()`. Read the ingestion pipeline and retrieval logic to map the full RAG flow.
97
-
98
- **Step 2 — Audit retrieval quality**
99
- Check for: fixed-size chunking that splits mid-sentence (context loss), no overlap between chunks (boundary information lost), embeddings generated without metadata (no filtering capability), retrieval without reranking (relevance drops after top-3), no chunk deduplication, and context window overflow (retrieved chunks exceed model limit).
100
-
101
- **Step 3 — Emit RAG pipeline**
102
- Emit: recursive text splitter with semantic boundaries, embedding generation with metadata, vector upsert with namespace, retrieval with reranking, and context window budget management.
103
-
104
- #### Example
105
-
106
- ```typescript
107
- // RAG pipeline — recursive chunking + pgvector + reranking
108
- import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
109
- import { OpenAIEmbeddings } from '@langchain/openai';
110
- import { PGVectorStore } from '@langchain/community/vectorstores/pgvector';
111
-
112
- // Ingestion: chunk → embed → store
113
- async function ingestDocument(doc: { content: string; metadata: Record<string, string> }) {
114
- const splitter = new RecursiveCharacterTextSplitter({
115
- chunkSize: 1000,
116
- chunkOverlap: 200,
117
- separators: ['\n## ', '\n### ', '\n\n', '\n', '. ', ' '],
118
- });
119
- const chunks = await splitter.createDocuments(
120
- [doc.content],
121
- [doc.metadata],
122
- );
123
-
124
- const embeddings = new OpenAIEmbeddings({ model: 'text-embedding-3-small' });
125
- await PGVectorStore.fromDocuments(chunks, embeddings, {
126
- postgresConnectionOptions: { connectionString: process.env.DATABASE_URL },
127
- tableName: 'documents',
128
- });
129
- }
130
-
131
- // Retrieval: query → vector search → rerank → top-k
132
- async function retrieve(query: string, topK = 5) {
133
- const store = await PGVectorStore.initialize(embeddings, pgConfig);
134
- const candidates = await store.similaritySearch(query, topK * 3); // over-retrieve
135
-
136
- // Rerank with Cohere
137
- const { results } = await cohere.rerank({
138
- model: 'rerank-english-v3.0',
139
- query,
140
- documents: candidates.map(c => c.pageContent),
141
- topN: topK,
142
- });
143
-
144
- return results.map(r => candidates[r.index]);
145
- }
146
- ```
147
-
148
- ---
149
-
150
- ### embedding-search
151
-
152
- Embedding-based search — semantic search, hybrid search (BM25 + vector), similarity thresholds, index optimization.
153
-
154
- #### Workflow
155
-
156
- **Step 1 — Detect search implementation**
157
- Use Grep to find search code: `similarity_search`, `vector_search`, `fts`, `tsvector`, `BM25`. Read search handlers to understand: query flow, ranking strategy, and result formatting.
158
-
159
- **Step 2 — Audit search quality**
160
- Check for: pure vector search without keyword fallback (misses exact matches), no similarity threshold (returns irrelevant results at low scores), missing query embedding cache (repeated queries re-embed), no hybrid scoring (BM25 for exact + vector for semantic), and unoptimized vector index (HNSW parameters not tuned).
161
-
162
- **Step 3 — Emit hybrid search**
163
- Emit: combined BM25 + vector search with reciprocal rank fusion, similarity threshold filtering, query embedding cache, and HNSW index tuning.
164
-
165
- #### Example
166
-
167
- ```typescript
168
- // Hybrid search — BM25 + vector with reciprocal rank fusion
169
- async function hybridSearch(query: string, limit = 10) {
170
- // Parallel: keyword (BM25) + semantic (vector)
171
- const [keywordResults, vectorResults] = await Promise.all([
172
- db.execute(sql`
173
- SELECT id, content, ts_rank(search_vector, plainto_tsquery(${query})) AS bm25_score
174
- FROM documents
175
- WHERE search_vector @@ plainto_tsquery(${query})
176
- ORDER BY bm25_score DESC LIMIT ${limit * 2}
177
- `),
178
- db.execute(sql`
179
- SELECT id, content, 1 - (embedding <=> ${await getEmbedding(query)}) AS vector_score
180
- FROM documents
181
- ORDER BY embedding <=> ${await getEmbedding(query)}
182
- LIMIT ${limit * 2}
183
- `),
184
- ]);
185
-
186
- // Reciprocal rank fusion (k=60)
187
- const scores = new Map<string, number>();
188
- const K = 60;
189
- keywordResults.forEach((r, i) => scores.set(r.id, (scores.get(r.id) || 0) + 1 / (K + i + 1)));
190
- vectorResults.forEach((r, i) => scores.set(r.id, (scores.get(r.id) || 0) + 1 / (K + i + 1)));
191
-
192
- return [...scores.entries()]
193
- .sort((a, b) => b[1] - a[1])
194
- .slice(0, limit)
195
- .filter(([_, score]) => score > 0.01); // threshold
196
- }
197
-
198
- // Embedding cache (avoid re-embedding repeated queries)
199
- const embeddingCache = new Map<string, number[]>();
200
- async function getEmbedding(text: string): Promise<number[]> {
201
- const cached = embeddingCache.get(text);
202
- if (cached) return cached;
203
- const { data } = await openai.embeddings.create({ model: 'text-embedding-3-small', input: text });
204
- embeddingCache.set(text, data[0].embedding);
205
- return data[0].embedding;
206
- }
207
- ```
208
-
209
- ---
210
-
211
- ### fine-tuning-guide
212
-
213
- Fine-tuning workflows — dataset preparation, training configuration, evaluation metrics, deployment, A/B testing.
214
-
215
- #### Workflow
216
-
217
- **Step 1 — Audit training data**
218
- Use Read to examine the dataset files. Check for: data format (JSONL with `messages` array), train/eval split (eval must not overlap with train), sufficient examples (minimum 50, recommended 200+), balanced class distribution, and PII in training data.
219
-
220
- **Step 2 — Prepare and validate dataset**
221
- Emit: JSONL formatter that validates each example, train/eval splitter with stratification, token count estimator (cost preview), and data quality checks (duplicate detection, format validation).
222
-
223
- **Step 3 — Execute fine-tuning and evaluate**
224
- Emit: fine-tune API call with hyperparameters, evaluation script that compares base vs fine-tuned on held-out set, and A/B deployment configuration.
225
-
226
- #### Example
227
-
228
- ```python
229
- # Fine-tuning workflow — prepare, train, evaluate
230
- import json
231
- import openai
232
- from sklearn.model_selection import train_test_split
233
-
234
- # Step 1: Prepare JSONL dataset
235
- def prepare_dataset(examples: list[dict], output_prefix: str):
236
- train, eval_set = train_test_split(examples, test_size=0.2, random_state=42)
237
-
238
- for split_name, split_data in [("train", train), ("eval", eval_set)]:
239
- path = f"{output_prefix}_{split_name}.jsonl"
240
- with open(path, "w") as f:
241
- for ex in split_data:
242
- f.write(json.dumps({"messages": [
243
- {"role": "system", "content": ex["system"]},
244
- {"role": "user", "content": ex["input"]},
245
- {"role": "assistant", "content": ex["output"]},
246
- ]}) + "\n")
247
- print(f"Wrote {len(split_data)} examples to {path}")
248
-
249
- # Step 2: Launch fine-tuning
250
- def start_fine_tune(train_file: str, eval_file: str):
251
- train_id = openai.files.create(file=open(train_file, "rb"), purpose="fine-tune").id
252
- eval_id = openai.files.create(file=open(eval_file, "rb"), purpose="fine-tune").id
253
-
254
- job = openai.fine_tuning.jobs.create(
255
- training_file=train_id,
256
- validation_file=eval_id,
257
- model="gpt-4o-mini-2024-07-18",
258
- hyperparameters={"n_epochs": 3, "batch_size": "auto", "learning_rate_multiplier": "auto"},
259
- )
260
- print(f"Fine-tuning job: {job.id} — status: {job.status}")
261
- return job
262
-
263
- # Step 3: Evaluate base vs fine-tuned
264
- def evaluate(base_model: str, ft_model: str, eval_set: list[dict]) -> dict:
265
- results = {"base": {"correct": 0}, "finetuned": {"correct": 0}}
266
- for ex in eval_set:
267
- for label, model in [("base", base_model), ("finetuned", ft_model)]:
268
- response = openai.chat.completions.create(
269
- model=model, messages=ex["messages"][:2], max_tokens=500,
270
- )
271
- if response.choices[0].message.content.strip() == ex["messages"][2]["content"].strip():
272
- results[label]["correct"] += 1
273
- for label in results:
274
- results[label]["accuracy"] = results[label]["correct"] / len(eval_set)
275
- return results
276
- ```
277
-
278
- ---
279
-
280
- ### llm-architect
281
-
282
- LLM system architecture — model selection, prompt engineering patterns, evaluation frameworks, cost optimization, multi-model routing, and guardrail design.
283
-
284
- #### Workflow
285
-
286
- **Step 1 — Assess LLM requirements**
287
- Understand the use case: what does the LLM need to do? Classify into:
288
- - **Generation**: open-ended text (blog, email, creative writing)
289
- - **Extraction**: structured data from unstructured input (JSON from text, entities, classification)
290
- - **Reasoning**: multi-step logic (math, code generation, planning)
291
- - **Conversation**: multi-turn dialogue with memory
292
- - **Agentic**: tool use, function calling, autonomous task execution
293
-
294
- For each class, identify: latency requirements (real-time < 2s, async < 30s, batch), accuracy requirements (critical = needs eval suite, casual = spot check), cost sensitivity (per-call budget), and data sensitivity (PII, HIPAA, can data leave the network?).
295
-
296
- **Step 2 — Model selection matrix**
297
- Based on requirements, recommend model tier:
298
-
299
- | Requirement | Recommended | Fallback |
300
- |------------|-------------|----------|
301
- | Fast + cheap (classification, routing) | Haiku / GPT-4o-mini | Local (Llama 3) |
302
- | Balanced (code, summaries, RAG) | Sonnet / GPT-4o | Haiku with retry |
303
- | Deep reasoning (architecture, math) | Opus / o1 | Sonnet with chain-of-thought |
304
- | On-premise required | Llama 3 / Mistral | Ollama local deployment |
305
- | Multimodal (vision + text) | Sonnet / GPT-4o | Local LLaVA |
306
-
307
- Emit: primary model, fallback model, estimated cost per 1K calls, and latency p50/p99.
308
-
309
- **Step 3 — Prompt architecture**
310
- Design the prompt structure:
311
- - **System prompt**: Role definition, constraints, output format. Keep under 500 tokens for cost efficiency.
312
- - **Few-shot examples**: 2-3 examples for extraction/classification tasks. Format matches expected output exactly.
313
- - **Chain-of-thought**: For reasoning tasks, explicitly request step-by-step thinking before final answer.
314
- - **Structured output**: JSON mode or tool use for extraction. Define schema with Zod/Pydantic for validation.
315
-
316
- **Step 4 — Guardrails and evaluation**
317
- Design safety and quality layers:
318
- - **Input guardrails**: PII detection, prompt injection detection, topic filtering
319
- - **Output guardrails**: Schema validation, hallucination checks, toxicity filtering
320
- - **Evaluation framework**: Define eval dataset (50+ examples), metrics (accuracy, latency, cost), and regression threshold (new prompt must not drop > 2% on any metric)
321
-
322
- Save architecture doc to `.rune/ai/llm-architecture.md`.
323
-
324
- #### Example
325
-
326
- ```typescript
327
- // Multi-model router with fallback
328
- interface ModelConfig {
329
- id: string;
330
- provider: 'anthropic' | 'openai' | 'local';
331
- costPer1kTokens: number;
332
- maxTokens: number;
333
- latencyP50Ms: number;
334
- }
335
-
336
- const MODELS: Record<string, ModelConfig> = {
337
- fast: {
338
- id: 'claude-haiku-4-5-20251001',
339
- provider: 'anthropic',
340
- costPer1kTokens: 0.001,
341
- maxTokens: 4096,
342
- latencyP50Ms: 200,
343
- },
344
- balanced: {
345
- id: 'claude-sonnet-4-6',
346
- provider: 'anthropic',
347
- costPer1kTokens: 0.01,
348
- maxTokens: 8192,
349
- latencyP50Ms: 800,
350
- },
351
- deep: {
352
- id: 'claude-opus-4-6',
353
- provider: 'anthropic',
354
- costPer1kTokens: 0.05,
355
- maxTokens: 16384,
356
- latencyP50Ms: 2000,
357
- },
358
- };
359
-
360
- type TaskComplexity = 'trivial' | 'standard' | 'complex';
361
-
362
- function selectModel(complexity: TaskComplexity): ModelConfig {
363
- const map: Record<TaskComplexity, string> = {
364
- trivial: 'fast',
365
- standard: 'balanced',
366
- complex: 'deep',
367
- };
368
- return MODELS[map[complexity]];
369
- }
370
-
371
- // Prompt architecture template
372
- const systemPrompt = `You are a ${role} assistant.
373
-
374
- CONSTRAINTS:
375
- - ${constraints.join('\n- ')}
376
-
377
- OUTPUT FORMAT:
378
- Return valid JSON matching this schema:
379
- ${JSON.stringify(outputSchema, null, 2)}
380
-
381
- Do not include explanations outside the JSON.`;
382
-
383
- // Guardrail: validate structured output
384
- import { z } from 'zod';
385
-
386
- const OutputSchema = z.object({
387
- classification: z.enum(['positive', 'negative', 'neutral']),
388
- confidence: z.number().min(0).max(1),
389
- reasoning: z.string().max(200),
390
- });
391
-
392
- function validateOutput(raw: string): z.infer<typeof OutputSchema> {
393
- const parsed = JSON.parse(raw);
394
- return OutputSchema.parse(parsed); // throws if invalid
395
- }
396
- ```
397
-
398
- ---
399
-
400
- ### prompt-patterns
401
-
402
- Reusable prompt engineering patterns — structured output, chain-of-thought, self-critique, tool use orchestration, and multi-turn memory management.
403
-
404
- #### Workflow
405
-
406
- **Step 1 — Identify the pattern**
407
- Match the user's task to a proven prompt pattern:
408
- - **Extraction**: Use JSON mode + schema definition + few-shot examples
409
- - **Classification**: Use enum output + confidence score + chain-of-thought
410
- - **Summarization**: Use structured summary template + length constraint + key point extraction
411
- - **Code generation**: Use system prompt with language constraints + test-driven output format
412
- - **Agent loop**: Use ReAct pattern (Thought → Action → Observation → repeat)
413
- - **Self-critique**: Use generate → critique → revise loop for quality-sensitive output
414
-
415
- **Step 2 — Apply the pattern**
416
- Generate the prompt following the selected pattern. Include:
417
- - System prompt (role + constraints + output format)
418
- - User message template (input variables marked with `{{variable}}`)
419
- - Few-shot examples (2-3, matching exact output format)
420
- - Validation schema (Zod/Pydantic for structured output)
421
-
422
- **Step 3 — Test harness**
423
- Emit a test file with 5+ test cases that validate the prompt produces correct output for known inputs. Include edge cases: empty input, very long input, ambiguous input, adversarial input.
424
-
425
- #### Example
426
-
427
- ```typescript
428
- // Pattern: ReAct Agent Loop
429
- const REACT_SYSTEM = `You are an agent that solves tasks using available tools.
430
-
431
- For each step, output EXACTLY this JSON format:
432
- {"thought": "reasoning about what to do next",
433
- "action": "tool_name",
434
- "action_input": "input for the tool"}
435
-
436
- After receiving an observation, continue with the next thought.
437
- When you have the final answer, output:
438
- {"thought": "I have the answer", "final_answer": "the answer"}
439
-
440
- Available tools:
441
- {{tools}}`;
442
-
443
- // Pattern: Self-Critique Loop
444
- async function generateWithCritique(prompt: string, maxRounds = 2) {
445
- let output = await llm.generate(prompt);
446
-
447
- for (let i = 0; i < maxRounds; i++) {
448
- const critique = await llm.generate(
449
- `Review this output for errors, omissions, and improvements:\n\n${output}\n\n` +
450
- `List specific issues. If no issues, respond with "APPROVED".`
451
- );
452
-
453
- if (critique.includes('APPROVED')) break;
454
-
455
- output = await llm.generate(
456
- `Original output:\n${output}\n\nCritique:\n${critique}\n\n` +
457
- `Revise the output to address all issues in the critique.`
458
- );
459
- }
460
-
461
- return output;
462
- }
463
- ```
464
-
465
- ---
35
+ | Skill | Model | Description |
36
+ |-------|-------|-------------|
37
+ | [llm-integration](skills/llm-integration.md) | sonnet | API client wrappers, streaming, structured output, retry + fallback chain, prompt versioning |
38
+ | [rag-patterns](skills/rag-patterns.md) | sonnet | Document chunking, embedding generation, vector store setup, retrieval, reranking |
39
+ | [embedding-search](skills/embedding-search.md) | sonnet | Semantic search, hybrid BM25 + vector, similarity thresholds, index optimization |
40
+ | [fine-tuning-guide](skills/fine-tuning-guide.md) | sonnet | Dataset preparation, training config, evaluation metrics, deployment, A/B testing |
41
+ | [llm-architect](skills/llm-architect.md) | opus | Model selection, prompt engineering, evaluation frameworks, cost optimization, guardrails |
42
+ | [prompt-patterns](skills/prompt-patterns.md) | sonnet | Structured output, chain-of-thought, self-critique, ReAct, multi-turn memory management |
43
+ | [ai-agents](skills/ai-agents.md) | sonnet | Stateful agents, RPC methods, scheduling, multi-agent coordination, MCP integration, HITL |
44
+ | [code-sandbox](skills/code-sandbox.md) | sonnet | Container isolation, resource limits, timeout enforcement, stateful sessions, output capture |
45
+ | [web-extraction](skills/web-extraction.md) | sonnet | Schema-driven extraction, anti-bot handling, prompt injection defense, multi-entity dedup |
46
+ | [deep-research](skills/deep-research.md) | sonnet | Iterative research loop with convergence, source attribution, confidence scoring |
466
47
 
467
48
  ## Connections
468
49
 
@@ -470,48 +51,31 @@ async function generateWithCritique(prompt: string, maxRounds = 2) {
470
51
  Calls → research (L3): lookup model documentation and best practices
471
52
  Calls → docs-seeker (L3): API reference for LLM providers
472
53
  Calls → verification (L3): validate pipeline correctness
54
+ Calls → @rune/devops (L4): ai-agents → edge-serverless for agent deployment (Workers, Lambda)
55
+ Calls → @rune/backend (L4): ai-agents → API patterns for agent endpoints and WebSocket handlers
56
+ Calls → sentinel (L2): code-sandbox security audit on container isolation
473
57
  Called By ← cook (L1): when AI/ML task detected
474
58
  Called By ← plan (L2): when AI architecture decisions needed
475
59
  Called By ← review (L2): when AI code under review
60
+ Called By ← mcp-builder (L2): ai-agents feeds MCP server patterns for agent-based MCP
61
+ ai-agents → code-sandbox: agents use sandboxes for executing LLM-generated code safely
62
+ code-sandbox → ai-agents: sandbox results feed back into agent state and conversation
63
+ web-extraction → rag-patterns: extracted structured data feeds into RAG ingestion pipeline
64
+ deep-research → web-extraction: research loop uses extraction for each discovered URL
65
+ deep-research → embedding-search: relevance scoring uses embeddings for semantic similarity
476
66
  ```
477
67
 
478
- ## Tech Stack Support
479
-
480
- | Provider | SDK | Vector Store | Notes |
481
- |----------|-----|-------------|-------|
482
- | OpenAI | openai v4+ | pgvector | Most common, JSON mode + function calling |
483
- | Anthropic | @anthropic-ai/sdk | Pinecone | Tool use + long context |
484
- | Cohere | cohere-ai | Weaviate | Reranking + embed v3 |
485
- | Local (Ollama) | ollama-js | ChromaDB | Self-hosted, privacy-sensitive |
486
-
487
- ## Constraints
488
-
489
- 1. MUST implement retry with exponential backoff on all LLM API calls — rate limits are guaranteed at scale.
490
- 2. MUST validate LLM output against a schema (Zod/Pydantic) — never trust raw text parsing for structured data.
491
- 3. MUST separate training and evaluation datasets — eval set leaking into training invalidates all metrics.
492
- 4. MUST set similarity thresholds on vector search — returning all results regardless of score degrades quality.
493
- 5. MUST NOT embed sensitive/PII data without explicit consent — embeddings are not easily deletable from vector stores.
494
-
495
68
  ## Sharp Edges
496
69
 
497
- | Failure Mode | Severity | Mitigation |
498
- |---|---|---|
499
- | LLM rate limit (429) crashes entire request pipeline | HIGH | Exponential backoff retry with jitter; fallback model chain for critical paths |
500
- | RAG retrieves irrelevant chunks due to fixed-size splitting across section boundaries | HIGH | Use recursive splitter with semantic separators (headings, paragraphs); include metadata for filtering |
501
- | Vector search returns high-similarity results that are factually wrong (semantic factual) | HIGH | Always rerank with cross-encoder; include source citation for verification |
502
- | Fine-tuned model overfits to training format, fails on slightly different inputs | HIGH | Include diverse input formats in training data; evaluate on out-of-distribution examples |
503
- | Embedding dimension mismatch between index and query model (model upgraded) | CRITICAL | Pin embedding model version; store model version in index metadata; re-embed on model change |
504
- | Token budget overflow when stuffing retrieved chunks into prompt | MEDIUM | Count tokens before assembly; truncate or drop lowest-ranked chunks to fit budget |
505
-
506
- ## Done When
507
-
508
- - LLM client has retry, structured output, streaming, and fallback chain
509
- - RAG pipeline ingests, chunks, embeds, stores, retrieves, and reranks correctly
510
- - Hybrid search returns relevant results for both keyword and semantic queries
511
- - Fine-tuning dataset validated, model trained, and eval shows improvement over base
512
- - All API calls handle rate limits and timeouts gracefully
513
- - Structured report emitted for each skill invoked
70
+ - **Rate limits**: MUST implement exponential backoff retry on all LLM API calls — guaranteed at scale.
71
+ - **Schema validation**: MUST validate LLM output with Zod/Pydantic — never trust raw text parsing.
72
+ - **Eval leakage**: MUST separate training and evaluation datasets leakage invalidates all metrics.
73
+ - **Similarity thresholds**: MUST set thresholds on vector search unrestricted results degrade quality.
74
+ - **PII in embeddings**: MUST NOT embed sensitive data without consent not easily deletable from vector stores.
75
+ - **Embedding model pinning**: Pin model version in index metadata dimension mismatch on upgrade is CRITICAL.
76
+ - **Prompt injection**: Web pages may contain adversarial content targeting extraction LLMs system prompt must block.
77
+ - **Sandbox escape**: Use rootless Docker or gVisor for high-security code execution environments.
514
78
 
515
79
  ## Cost Profile
516
80
 
517
- ~10,000–18,000 tokens per full pack run (all 4 skills). Individual skill: ~2,500–5,000 tokens. Sonnet default. Use haiku for code detection scans; escalate to sonnet for pipeline design and evaluation strategy.
81
+ ~24,000–40,000 tokens per full pack run (all 10 skills). Individual skill: ~2,500–5,000 tokens. Sonnet default. Use haiku for code detection scans; escalate to sonnet for pipeline design, extraction strategy, and research loop orchestration.