q-kdb-code-review
AI-powered code review for Q/kdb+ — catch bugs, performance issues, and security vulnerabilities in the most terse language in quantitative finance.
What it does
Reviews Q/kdb+ code with deep understanding of Q idioms, performance patterns, and common pitfalls. Built for quant developers, kdb+ DBAs, and trading infrastructure teams.
Catches:
- Type errors in implicit casts (e.g., mixing longs and floats in comparisons)
- Rank errors from wrong argument counts in function calls
- Unescaped signals in protected evaluation
- Memory-inefficient queries (selecting all columns when only some are needed)
- Missing
peach parallelism opportunities for embarrassingly parallel operations
- Unsafe
eval/value usage on user-supplied strings (Q injection)
- Unlocked tables during concurrent inserts
- Missing
`g# grouped attributes on high-cardinality join columns
- N-squared joins that should be
aj (asof joins) or wj (window joins)
- Race conditions in timer callbacks (.z.ts)
- Unprotected IPC handlers (.z.pg, .z.ps) and exposed .z.pw
Strictness modes:
| Mode |
What it checks |
standard |
Bugs, correctness, type errors, join semantics, null handling |
strict |
Everything in standard + performance (attributes, peach, vector ops) + style |
security |
Everything in standard + injection via string eval, unprotected IPC handlers, exposed .z.pw, port exposure |
Intelligent routing via Astrai: Complex algorithmic Q (custom signal generation, real-time CEP) routes to powerful models. Simple table operations (selects, inserts, schema definitions) route to cheaper, faster models. You get the best result at the lowest cost.
BYOK (Bring Your Own Keys): Your provider API keys, your billing. Astrai routes to the best model among your configured providers.
Setup
- Get a free API key at as-trai.com
- Set your API key:
export ASTRAI_API_KEY="your_key_here"
- Optionally add provider keys for BYOK routing:
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENAI_API_KEY="sk-..."
- Run
/review-q on any .q file
Usage
/review-q Review current Q file
/review-q --strict Strict mode: bugs + performance + style
/review-q --focus security Security mode: eval injection, IPC, .z.pw
/review-q --file tick.q Review a specific file
Example output
Reviewing tick.q (strict mode)...
Model: claude-opus-4-6 via Astrai
Found 3 issues:
[CRITICAL] Line 12: Missing `s# attribute on time column
`trade` table uses `aj` but `time` column lacks sorted attribute.
Without `s#`, asof join scans linearly — O(n) instead of O(log n).
Fix: trade: `trade upsert update `s#time from trade
[WARNING] Line 34: Using `each` where vector operation suffices
{x*y} each' (price;qty) can be replaced with price*qty
Vector multiply is ~100x faster than each-both.
[INFO] Line 45: Consider `peach` for independent symbol processing
Processing each symbol sequentially. Since operations are independent,
`peach` would utilize all cores.
Fix: results: func peach syms
Summary: 1 critical, 1 warning, 1 info. Focus on the missing sorted
attribute — it will cause aj performance to degrade from microseconds
to milliseconds at scale.
Environment Variables
| Variable |
Required |
Description |
ASTRAI_API_KEY |
Yes |
API key from as-trai.com |
ANTHROPIC_API_KEY |
No |
BYOK: Anthropic provider key |
OPENAI_API_KEY |
No |
BYOK: OpenAI provider key |
GOOGLE_API_KEY |
No |
BYOK: Google AI provider key |
DEEPSEEK_API_KEY |
No |
BYOK: DeepSeek provider key |
MISTRAL_API_KEY |
No |
BYOK: Mistral provider key |
GROQ_API_KEY |
No |
BYOK: Groq provider key |
TOGETHER_API_KEY |
No |
BYOK: Together AI provider key |
FIREWORKS_API_KEY |
No |
BYOK: Fireworks AI provider key |
COHERE_API_KEY |
No |
BYOK: Cohere provider key |
PERPLEXITY_API_KEY |
No |
BYOK: Perplexity provider key |
REVIEW_STRICTNESS |
No |
Default strictness: standard, strict, or security |
External Endpoints
| Endpoint |
Purpose |
as-trai.com/v1/chat/completions |
Astrai inference router — routes Q review requests to the optimal model |
Security & Privacy
- No code storage: Your Q code is sent to the selected AI provider for inference and is not stored by Astrai.
- BYOK: When you provide your own provider keys, requests go directly through Astrai's router to your provider account. Astrai does not store or log your provider keys beyond the request lifecycle.
- Transport: All communication uses HTTPS/TLS.
- No telemetry: The skill does not send analytics or telemetry data. Only the review request goes to Astrai.
- Local processing: File reading and result formatting happen entirely on your machine.
Why Q needs specialized review
Q is unlike any mainstream programming language:
- Extreme terseness: A single line of Q can express what takes 20 lines in Python. This density makes bugs nearly invisible during manual review.
- Implicit type coercion: Q silently coerces types in many operations. Comparing a long to a float, or joining on mismatched key types, can produce silently wrong results.
- 1000x performance gaps: The difference between idiomatic and naive Q is not 2x or 10x — it is often 1000x. Missing a sorted attribute on a time column turns an O(log n) asof join into O(n). Using
each instead of vector operations adds interpreter overhead per element.
- Adverb complexity: Q's adverbs (
/, \, ', /:, \:, ':) modify function behavior in powerful but subtle ways. +/ is reduce-add, +\ is scan-add, +' is each-both-add. Confusing these causes wrong results, not errors.
- Most AI models struggle: Without Q-specific prompting, general-purpose AI models treat Q code as line noise. This skill provides detailed system prompts that teach the model Q semantics, kdb+ internals, and finance-domain patterns.
Pricing
Uses Astrai's inference routing. Your costs depend on the models selected:
| Plan |
Rate |
Includes |
| Free |
$0 |
1,000 requests/day |
| Pro |
$49/mo |
50,000 requests/day, priority routing |
| Business |
$199/mo |
Unlimited requests, dedicated support |
With BYOK, you pay your provider directly at their rates. Astrai's routing is included in the plan price.
1---
2name: q-kdb-code-review
3description: AI-powered code review for Q/kdb+ — catch bugs in the most terse language in finance
4version: 1.0.0
5homepage: https://github.com/beee003/astrai-openclaw
6metadata:
7 source: https://skillmd.com/skills/modbender/q-kdb-code-review
8 clawdbot:
9 emoji: "⚡"
10 requires:
11 env: ["ASTRAI_API_KEY"]
12 primaryEnv: "ASTRAI_API_KEY"
13 files: ["plugin.py", "config.example.toml"]
14tags: [q, kdb, kdb-plus, quant, finance, code-review, hft, trading, timeseries]
15---
16
17# q-kdb-code-review
18
19AI-powered code review for Q/kdb+ — catch bugs, performance issues, and security vulnerabilities in the most terse language in quantitative finance.
20
21## What it does
22
23Reviews Q/kdb+ code with deep understanding of Q idioms, performance patterns, and common pitfalls. Built for quant developers, kdb+ DBAs, and trading infrastructure teams.
24
25**Catches:**
26
27- Type errors in implicit casts (e.g., mixing longs and floats in comparisons)
28- Rank errors from wrong argument counts in function calls
29- Unescaped signals in protected evaluation
30- Memory-inefficient queries (selecting all columns when only some are needed)
31- Missing `peach` parallelism opportunities for embarrassingly parallel operations
32- Unsafe `eval`/`value` usage on user-supplied strings (Q injection)
33- Unlocked tables during concurrent inserts
34- Missing `` `g# `` grouped attributes on high-cardinality join columns
35- N-squared joins that should be `aj` (asof joins) or `wj` (window joins)
36- Race conditions in timer callbacks (.z.ts)
37- Unprotected IPC handlers (.z.pg, .z.ps) and exposed .z.pw
38
39**Strictness modes:**
40
41| Mode | What it checks |
42|------|---------------|
43| `standard` | Bugs, correctness, type errors, join semantics, null handling |
44| `strict` | Everything in standard + performance (attributes, peach, vector ops) + style |
45| `security` | Everything in standard + injection via string eval, unprotected IPC handlers, exposed .z.pw, port exposure |
46
47**Intelligent routing via Astrai:** Complex algorithmic Q (custom signal generation, real-time CEP) routes to powerful models. Simple table operations (selects, inserts, schema definitions) route to cheaper, faster models. You get the best result at the lowest cost.
48
49**BYOK (Bring Your Own Keys):** Your provider API keys, your billing. Astrai routes to the best model among your configured providers.
50
51## Setup
52
531. **Get a free API key** at [as-trai.com](https://as-trai.com)
542. **Set your API key:**
55 ```bash
56 export ASTRAI_API_KEY="your_key_here"
57 ```
583. **Optionally add provider keys** for BYOK routing:
59 ```bash
60 export ANTHROPIC_API_KEY="sk-ant-..."
61 export OPENAI_API_KEY="sk-..."
62 ```
634. **Run `/review-q`** on any `.q` file
64
65## Usage
66
67```
68/review-q Review current Q file
69/review-q --strict Strict mode: bugs + performance + style
70/review-q --focus security Security mode: eval injection, IPC, .z.pw
71/review-q --file tick.q Review a specific file
72```
73
74### Example output
75
76```
77Reviewing tick.q (strict mode)...
78Model: claude-opus-4-6 via Astrai
79
80Found 3 issues:
81
82[CRITICAL] Line 12: Missing `s# attribute on time column
83 `trade` table uses `aj` but `time` column lacks sorted attribute.
84 Without `s#`, asof join scans linearly — O(n) instead of O(log n).
85 Fix: trade: `trade upsert update `s#time from trade
86
87[WARNING] Line 34: Using `each` where vector operation suffices
88 {x*y} each' (price;qty) can be replaced with price*qty
89 Vector multiply is ~100x faster than each-both.
90
91[INFO] Line 45: Consider `peach` for independent symbol processing
92 Processing each symbol sequentially. Since operations are independent,
93 `peach` would utilize all cores.
94 Fix: results: func peach syms
95
96Summary: 1 critical, 1 warning, 1 info. Focus on the missing sorted
97attribute — it will cause aj performance to degrade from microseconds
98to milliseconds at scale.
99```
100
101## Environment Variables
102
103| Variable | Required | Description |
104|----------|----------|-------------|
105| `ASTRAI_API_KEY` | Yes | API key from [as-trai.com](https://as-trai.com) |
106| `ANTHROPIC_API_KEY` | No | BYOK: Anthropic provider key |
107| `OPENAI_API_KEY` | No | BYOK: OpenAI provider key |
108| `GOOGLE_API_KEY` | No | BYOK: Google AI provider key |
109| `DEEPSEEK_API_KEY` | No | BYOK: DeepSeek provider key |
110| `MISTRAL_API_KEY` | No | BYOK: Mistral provider key |
111| `GROQ_API_KEY` | No | BYOK: Groq provider key |
112| `TOGETHER_API_KEY` | No | BYOK: Together AI provider key |
113| `FIREWORKS_API_KEY` | No | BYOK: Fireworks AI provider key |
114| `COHERE_API_KEY` | No | BYOK: Cohere provider key |
115| `PERPLEXITY_API_KEY` | No | BYOK: Perplexity provider key |
116| `REVIEW_STRICTNESS` | No | Default strictness: `standard`, `strict`, or `security` |
117
118## External Endpoints
119
120| Endpoint | Purpose |
121|----------|---------|
122| `as-trai.com/v1/chat/completions` | Astrai inference router — routes Q review requests to the optimal model |
123
124## Security & Privacy
125
126- **No code storage:** Your Q code is sent to the selected AI provider for inference and is not stored by Astrai.
127- **BYOK:** When you provide your own provider keys, requests go directly through Astrai's router to your provider account. Astrai does not store or log your provider keys beyond the request lifecycle.
128- **Transport:** All communication uses HTTPS/TLS.
129- **No telemetry:** The skill does not send analytics or telemetry data. Only the review request goes to Astrai.
130- **Local processing:** File reading and result formatting happen entirely on your machine.
131
132## Why Q needs specialized review
133
134Q is unlike any mainstream programming language:
135
136- **Extreme terseness:** A single line of Q can express what takes 20 lines in Python. This density makes bugs nearly invisible during manual review.
137- **Implicit type coercion:** Q silently coerces types in many operations. Comparing a long to a float, or joining on mismatched key types, can produce silently wrong results.
138- **1000x performance gaps:** The difference between idiomatic and naive Q is not 2x or 10x — it is often 1000x. Missing a sorted attribute on a time column turns an O(log n) asof join into O(n). Using `each` instead of vector operations adds interpreter overhead per element.
139- **Adverb complexity:** Q's adverbs (`/`, `\`, `'`, `/:`, `\:`, `':`) modify function behavior in powerful but subtle ways. `+/` is reduce-add, `+\` is scan-add, `+'` is each-both-add. Confusing these causes wrong results, not errors.
140- **Most AI models struggle:** Without Q-specific prompting, general-purpose AI models treat Q code as line noise. This skill provides detailed system prompts that teach the model Q semantics, kdb+ internals, and finance-domain patterns.
141
142## Pricing
143
144Uses Astrai's inference routing. Your costs depend on the models selected:
145
146| Plan | Rate | Includes |
147|------|------|----------|
148| Free | $0 | 1,000 requests/day |
149| Pro | $49/mo | 50,000 requests/day, priority routing |
150| Business | $199/mo | Unlimited requests, dedicated support |
151
152With BYOK, you pay your provider directly at their rates. Astrai's routing is included in the plan price.