stacksagent 1.0.0
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.
- package/dist/assets/.agent/workflows/stacks-agent.md +71 -0
- package/dist/assets/.claude/settings.local.json +36 -0
- package/dist/assets/.claude/skills/stacks-agent/SKILL.md +219 -0
- package/dist/assets/.claude/skills/stacks-agent/data/bns.csv +11 -0
- package/dist/assets/.claude/skills/stacks-agent/data/clarity-syntax.csv +62 -0
- package/dist/assets/.claude/skills/stacks-agent/data/contract-templates.csv +15 -0
- package/dist/assets/.claude/skills/stacks-agent/data/defi-protocols.csv +16 -0
- package/dist/assets/.claude/skills/stacks-agent/data/deployment.csv +26 -0
- package/dist/assets/.claude/skills/stacks-agent/data/security-patterns.csv +16 -0
- package/dist/assets/.claude/skills/stacks-agent/data/stacking.csv +16 -0
- package/dist/assets/.claude/skills/stacks-agent/data/stacks-js.csv +31 -0
- package/dist/assets/.claude/skills/stacks-agent/scripts/core.py +165 -0
- package/dist/assets/.claude/skills/stacks-agent/scripts/search.py +62 -0
- package/dist/assets/.codex/skills/stacks-agent/SKILL.md +126 -0
- package/dist/assets/.cursor/commands/stacks-agent.md +50 -0
- package/dist/assets/.github/prompts/stacks-agent.prompt.md +80 -0
- package/dist/assets/.kiro/steering/stacks-agent.md +78 -0
- package/dist/assets/.shared/stacks-agent/data/bns.csv +11 -0
- package/dist/assets/.shared/stacks-agent/data/clarity-syntax.csv +62 -0
- package/dist/assets/.shared/stacks-agent/data/contract-templates.csv +15 -0
- package/dist/assets/.shared/stacks-agent/data/defi-protocols.csv +16 -0
- package/dist/assets/.shared/stacks-agent/data/deployment.csv +26 -0
- package/dist/assets/.shared/stacks-agent/data/security-patterns.csv +16 -0
- package/dist/assets/.shared/stacks-agent/data/stacking.csv +16 -0
- package/dist/assets/.shared/stacks-agent/data/stacks-js.csv +31 -0
- package/dist/assets/.shared/stacks-agent/scripts/core.py +165 -0
- package/dist/assets/.shared/stacks-agent/scripts/search.py +62 -0
- package/dist/assets/.windsurf/workflows/stacks-agent.md +58 -0
- package/dist/commands/init.d.ts +6 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +53 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +31 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/versions.d.ts +2 -0
- package/dist/commands/versions.d.ts.map +1 -0
- package/dist/commands/versions.js +33 -0
- package/dist/commands/versions.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Core search engine using BM25 ranking with regex matching
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import csv
|
|
6
|
+
import re
|
|
7
|
+
import math
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import List, Dict, Any, Optional
|
|
10
|
+
from collections import defaultdict
|
|
11
|
+
|
|
12
|
+
# Domain to CSV file mapping
|
|
13
|
+
DOMAINS = {
|
|
14
|
+
'clarity': 'clarity-syntax.csv',
|
|
15
|
+
'templates': 'contract-templates.csv',
|
|
16
|
+
'security': 'security-patterns.csv',
|
|
17
|
+
'defi': 'defi-protocols.csv',
|
|
18
|
+
'stacksjs': 'stacks-js.csv',
|
|
19
|
+
'bns': 'bns.csv',
|
|
20
|
+
'stacking': 'stacking.csv',
|
|
21
|
+
'deployment': 'deployment.csv'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
# Auto-detection keywords
|
|
25
|
+
DOMAIN_KEYWORDS = {
|
|
26
|
+
'clarity': ['define', 'uint', 'principal', 'let', 'begin', 'asserts', 'unwrap', 'function', 'type', 'syntax'],
|
|
27
|
+
'templates': ['token', 'nft', 'sip-010', 'sip-009', 'vault', 'dao', 'template', 'contract'],
|
|
28
|
+
'security': ['vulnerability', 'security', 'audit', 'attack', 'safe', 'check', 'exploit'],
|
|
29
|
+
'defi': ['swap', 'pool', 'liquidity', 'alex', 'velar', 'bitflow', 'zest', 'borrow', 'lend', 'boost'],
|
|
30
|
+
'stacksjs': ['javascript', 'stacks.js', 'connect', 'wallet', 'frontend', 'react', 'typescript'],
|
|
31
|
+
'bns': ['bns', 'name', 'domain', '.btc', 'resolve', 'register'],
|
|
32
|
+
'stacking': ['stacking', 'pox', 'delegate', 'pool', 'reward', 'cycle', 'bitcoin'],
|
|
33
|
+
'deployment': ['deploy', 'mainnet', 'testnet', 'clarinet', 'devnet']
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class BM25:
|
|
38
|
+
"""BM25 ranking algorithm"""
|
|
39
|
+
|
|
40
|
+
def __init__(self, documents: List[str], k1: float = 1.5, b: float = 0.75):
|
|
41
|
+
self.k1 = k1
|
|
42
|
+
self.b = b
|
|
43
|
+
self.documents = documents
|
|
44
|
+
self.doc_len = [len(doc.split()) for doc in documents]
|
|
45
|
+
self.avgdl = sum(self.doc_len) / len(documents) if documents else 0
|
|
46
|
+
self.doc_freqs = self._calc_doc_freqs()
|
|
47
|
+
self.idf = self._calc_idf()
|
|
48
|
+
|
|
49
|
+
def _calc_doc_freqs(self) -> Dict[str, int]:
|
|
50
|
+
freqs = defaultdict(int)
|
|
51
|
+
for doc in self.documents:
|
|
52
|
+
for term in set(doc.lower().split()):
|
|
53
|
+
freqs[term] += 1
|
|
54
|
+
return freqs
|
|
55
|
+
|
|
56
|
+
def _calc_idf(self) -> Dict[str, float]:
|
|
57
|
+
idf = {}
|
|
58
|
+
n = len(self.documents)
|
|
59
|
+
for term, df in self.doc_freqs.items():
|
|
60
|
+
idf[term] = math.log((n - df + 0.5) / (df + 0.5) + 1)
|
|
61
|
+
return idf
|
|
62
|
+
|
|
63
|
+
def score(self, query: str, doc_idx: int) -> float:
|
|
64
|
+
score = 0.0
|
|
65
|
+
doc = self.documents[doc_idx].lower()
|
|
66
|
+
doc_terms = doc.split()
|
|
67
|
+
term_freqs = defaultdict(int)
|
|
68
|
+
for term in doc_terms:
|
|
69
|
+
term_freqs[term] += 1
|
|
70
|
+
|
|
71
|
+
for term in query.lower().split():
|
|
72
|
+
if term not in self.idf:
|
|
73
|
+
continue
|
|
74
|
+
tf = term_freqs[term]
|
|
75
|
+
idf = self.idf[term]
|
|
76
|
+
dl = self.doc_len[doc_idx]
|
|
77
|
+
score += idf * (tf * (self.k1 + 1)) / (tf + self.k1 * (1 - self.b + self.b * dl / self.avgdl))
|
|
78
|
+
|
|
79
|
+
return score
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def detect_domain(query: str) -> str:
|
|
83
|
+
"""Auto-detect domain based on query keywords"""
|
|
84
|
+
query_lower = query.lower()
|
|
85
|
+
scores = {}
|
|
86
|
+
|
|
87
|
+
for domain, keywords in DOMAIN_KEYWORDS.items():
|
|
88
|
+
score = sum(1 for kw in keywords if kw in query_lower)
|
|
89
|
+
if score > 0:
|
|
90
|
+
scores[domain] = score
|
|
91
|
+
|
|
92
|
+
if scores:
|
|
93
|
+
return max(scores, key=scores.get)
|
|
94
|
+
return 'templates' # Default to templates
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def load_data(domain: str) -> List[Dict[str, Any]]:
|
|
98
|
+
"""Load CSV data for a domain"""
|
|
99
|
+
data_dir = Path(__file__).parent.parent / 'data'
|
|
100
|
+
csv_file = data_dir / DOMAINS[domain]
|
|
101
|
+
|
|
102
|
+
if not csv_file.exists():
|
|
103
|
+
return []
|
|
104
|
+
|
|
105
|
+
with open(csv_file, 'r', encoding='utf-8') as f:
|
|
106
|
+
reader = csv.DictReader(f)
|
|
107
|
+
return list(reader)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def search(
|
|
111
|
+
query: str,
|
|
112
|
+
domain: str = 'auto',
|
|
113
|
+
max_results: int = 5
|
|
114
|
+
) -> List[Dict[str, Any]]:
|
|
115
|
+
"""
|
|
116
|
+
Search knowledge base using BM25 + regex
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
query: Search query
|
|
120
|
+
domain: Domain to search or 'auto' for auto-detection
|
|
121
|
+
max_results: Maximum results to return
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
List of matching records
|
|
125
|
+
"""
|
|
126
|
+
# Auto-detect domain if needed
|
|
127
|
+
if domain == 'auto':
|
|
128
|
+
domain = detect_domain(query)
|
|
129
|
+
|
|
130
|
+
# Load data
|
|
131
|
+
data = load_data(domain)
|
|
132
|
+
if not data:
|
|
133
|
+
return []
|
|
134
|
+
|
|
135
|
+
# Create searchable text for each record
|
|
136
|
+
def record_to_text(record: Dict) -> str:
|
|
137
|
+
return ' '.join(str(v) for v in record.values())
|
|
138
|
+
|
|
139
|
+
documents = [record_to_text(r) for r in data]
|
|
140
|
+
|
|
141
|
+
# BM25 scoring
|
|
142
|
+
bm25 = BM25(documents)
|
|
143
|
+
scores = [(i, bm25.score(query, i)) for i in range(len(documents))]
|
|
144
|
+
|
|
145
|
+
# Regex boost for exact matches
|
|
146
|
+
try:
|
|
147
|
+
query_pattern = re.compile(re.escape(query), re.IGNORECASE)
|
|
148
|
+
for i, (idx, score) in enumerate(scores):
|
|
149
|
+
if query_pattern.search(documents[idx]):
|
|
150
|
+
scores[i] = (idx, score * 2) # Boost exact matches
|
|
151
|
+
except re.error:
|
|
152
|
+
pass # Skip regex boost if pattern is invalid
|
|
153
|
+
|
|
154
|
+
# Sort by score and return top results
|
|
155
|
+
scores.sort(key=lambda x: x[1], reverse=True)
|
|
156
|
+
|
|
157
|
+
results = []
|
|
158
|
+
for idx, score in scores[:max_results]:
|
|
159
|
+
if score > 0:
|
|
160
|
+
result = data[idx].copy()
|
|
161
|
+
result['_score'] = round(score, 3)
|
|
162
|
+
result['_domain'] = domain
|
|
163
|
+
results.append(result)
|
|
164
|
+
|
|
165
|
+
return results
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Stacks Agent Skill - Search Engine
|
|
4
|
+
BM25 + regex hybrid search across knowledge databases
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
# Add parent directory to path for imports
|
|
12
|
+
sys.path.insert(0, str(Path(__file__).parent))
|
|
13
|
+
|
|
14
|
+
from core import search, DOMAINS
|
|
15
|
+
|
|
16
|
+
def main():
|
|
17
|
+
parser = argparse.ArgumentParser(
|
|
18
|
+
description='Search Stacks Agent knowledge base'
|
|
19
|
+
)
|
|
20
|
+
parser.add_argument('query', help='Search query')
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
'--domain', '-d',
|
|
23
|
+
choices=list(DOMAINS.keys()) + ['auto'],
|
|
24
|
+
default='auto',
|
|
25
|
+
help='Domain to search (default: auto-detect)'
|
|
26
|
+
)
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
'--max-results', '-n',
|
|
29
|
+
type=int,
|
|
30
|
+
default=5,
|
|
31
|
+
help='Maximum results to return (default: 5)'
|
|
32
|
+
)
|
|
33
|
+
parser.add_argument(
|
|
34
|
+
'--format', '-f',
|
|
35
|
+
choices=['text', 'json'],
|
|
36
|
+
default='text',
|
|
37
|
+
help='Output format (default: text)'
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
args = parser.parse_args()
|
|
41
|
+
|
|
42
|
+
results = search(
|
|
43
|
+
query=args.query,
|
|
44
|
+
domain=args.domain,
|
|
45
|
+
max_results=args.max_results
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if args.format == 'json':
|
|
49
|
+
import json
|
|
50
|
+
print(json.dumps(results, indent=2))
|
|
51
|
+
else:
|
|
52
|
+
if not results:
|
|
53
|
+
print(f"No results found for: {args.query}")
|
|
54
|
+
else:
|
|
55
|
+
for i, result in enumerate(results, 1):
|
|
56
|
+
print(f"\n--- Result {i} (Score: {result.get('_score', 0)}) ---")
|
|
57
|
+
for key, value in result.items():
|
|
58
|
+
if not key.startswith('_'):
|
|
59
|
+
print(f"{key}: {value}")
|
|
60
|
+
|
|
61
|
+
if __name__ == '__main__':
|
|
62
|
+
main()
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Stacks Agent - OpenAI Codex Skill
|
|
2
|
+
|
|
3
|
+
Stacks blockchain development intelligence for Codex.
|
|
4
|
+
|
|
5
|
+
## Skill Overview
|
|
6
|
+
|
|
7
|
+
AI-powered assistance for building on Stacks - Bitcoin's smart contract layer.
|
|
8
|
+
|
|
9
|
+
## Capabilities
|
|
10
|
+
|
|
11
|
+
- Generate and audit Clarity smart contracts
|
|
12
|
+
- SIP-010 fungible tokens and SIP-009 NFTs
|
|
13
|
+
- DeFi protocol integration (Alex, Velar, Bitflow, Zest)
|
|
14
|
+
- Security vulnerability detection and fixes
|
|
15
|
+
- Stacks.js frontend integration
|
|
16
|
+
- BNS name system operations
|
|
17
|
+
- PoX stacking and pool delegation
|
|
18
|
+
- Deployment guides (testnet, mainnet, devnet)
|
|
19
|
+
|
|
20
|
+
## Knowledge Base
|
|
21
|
+
|
|
22
|
+
170+ searchable entries across 8 domains:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
python3 .shared/stacks-agent/scripts/search.py "<query>" --domain <domain>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Domains**:
|
|
29
|
+
- `clarity` - 61 functions and types
|
|
30
|
+
- `templates` - 14 contract templates
|
|
31
|
+
- `security` - 15 security patterns
|
|
32
|
+
- `defi` - 15 DeFi protocols
|
|
33
|
+
- `stacksjs` - 30 JavaScript snippets
|
|
34
|
+
- `bns` - 10 name system operations
|
|
35
|
+
- `stacking` - 15 stacking guides
|
|
36
|
+
- `deployment` - 25 deployment steps
|
|
37
|
+
|
|
38
|
+
## Workflow
|
|
39
|
+
|
|
40
|
+
1. **Analyze** user request (contract type, features, network)
|
|
41
|
+
2. **Search** knowledge base for relevant patterns
|
|
42
|
+
3. **Generate** code following Clarity best practices
|
|
43
|
+
4. **Apply** security patterns automatically
|
|
44
|
+
5. **Provide** deployment instructions
|
|
45
|
+
|
|
46
|
+
## Code Generation Rules
|
|
47
|
+
|
|
48
|
+
### Always Include
|
|
49
|
+
- Access control checks (`tx-sender` validation)
|
|
50
|
+
- Error handling (`try!`, `unwrap!`)
|
|
51
|
+
- Input validation (`asserts!`)
|
|
52
|
+
- Named error constants (`ERR-*`)
|
|
53
|
+
- Kebab-case naming
|
|
54
|
+
- Documentation comments
|
|
55
|
+
|
|
56
|
+
### Never Include
|
|
57
|
+
- `unwrap-panic` in production code
|
|
58
|
+
- Hardcoded magic numbers
|
|
59
|
+
- Unvalidated external calls
|
|
60
|
+
- Missing return value checks
|
|
61
|
+
|
|
62
|
+
## Security Patterns
|
|
63
|
+
|
|
64
|
+
### Critical
|
|
65
|
+
- Validate `tx-sender` for sensitive operations
|
|
66
|
+
- Check all transfer return values
|
|
67
|
+
- Handle errors explicitly
|
|
68
|
+
|
|
69
|
+
### High
|
|
70
|
+
- Validate all inputs
|
|
71
|
+
- Prevent division by zero
|
|
72
|
+
- Update state before external calls
|
|
73
|
+
|
|
74
|
+
### Medium
|
|
75
|
+
- Prevent self-transfers
|
|
76
|
+
- Restrict minting functions
|
|
77
|
+
- Use `tx-sender` not `contract-caller`
|
|
78
|
+
|
|
79
|
+
## Example Outputs
|
|
80
|
+
|
|
81
|
+
### Token Contract
|
|
82
|
+
```clarity
|
|
83
|
+
(define-fungible-token my-token u1000000)
|
|
84
|
+
(define-constant ERR-UNAUTHORIZED (err u100))
|
|
85
|
+
(define-constant ERR-INVALID-AMOUNT (err u101))
|
|
86
|
+
|
|
87
|
+
(define-public (transfer (amount uint) (recipient principal))
|
|
88
|
+
(begin
|
|
89
|
+
(asserts! (> amount u0) ERR-INVALID-AMOUNT)
|
|
90
|
+
(try! (ft-transfer? my-token amount tx-sender recipient))
|
|
91
|
+
(ok true)))
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### DeFi Integration
|
|
95
|
+
```clarity
|
|
96
|
+
;; Swap on Alex
|
|
97
|
+
(contract-call?
|
|
98
|
+
'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-swap-pool-v1-1
|
|
99
|
+
swap-helper
|
|
100
|
+
.token-wstx
|
|
101
|
+
.age000-governance-token
|
|
102
|
+
u100000000
|
|
103
|
+
u100000000
|
|
104
|
+
u1000000
|
|
105
|
+
u1)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Networks
|
|
109
|
+
|
|
110
|
+
- **Mainnet**: SP... addresses (production)
|
|
111
|
+
- **Testnet**: ST... addresses (free STX for testing)
|
|
112
|
+
- **Devnet**: Local Clarinet development
|
|
113
|
+
|
|
114
|
+
## Standards
|
|
115
|
+
|
|
116
|
+
- SIP-010 (FT): `SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard`
|
|
117
|
+
- SIP-009 (NFT): `SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait`
|
|
118
|
+
|
|
119
|
+
## Resources
|
|
120
|
+
|
|
121
|
+
- https://docs.stacks.co
|
|
122
|
+
- https://explorer.hiro.so
|
|
123
|
+
- https://github.com/hirosystems/clarinet
|
|
124
|
+
|
|
125
|
+
**Version**: 1.0.0
|
|
126
|
+
**Author**: kai-builder
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Stacks Agent - Cursor Command
|
|
2
|
+
|
|
3
|
+
AI-powered intelligence for building Stacks blockchain applications.
|
|
4
|
+
|
|
5
|
+
## Command
|
|
6
|
+
Use `/stacks-agent` to activate this workflow for Stacks development tasks.
|
|
7
|
+
|
|
8
|
+
## Capabilities
|
|
9
|
+
|
|
10
|
+
- **Clarity Contracts**: Generate, audit, and deploy smart contracts
|
|
11
|
+
- **Token Standards**: SIP-010 (fungible) and SIP-009 (NFT) templates
|
|
12
|
+
- **DeFi Integration**: Alex, Velar, Bitflow, Zest, Boost, Faktory
|
|
13
|
+
- **Security Analysis**: Vulnerability detection and best practices
|
|
14
|
+
- **Stacks.js**: Frontend integration code snippets
|
|
15
|
+
- **BNS**: Bitcoin Name System operations
|
|
16
|
+
- **Stacking**: PoX stacking and pool delegation
|
|
17
|
+
|
|
18
|
+
## Knowledge Search
|
|
19
|
+
|
|
20
|
+
Use the search script to query the knowledge base:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
python3 .shared/stacks-agent/scripts/search.py "<query>" --domain <domain>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Available domains**: clarity, templates, security, defi, stacksjs, bns, stacking, deployment, auto
|
|
27
|
+
|
|
28
|
+
## Workflow
|
|
29
|
+
|
|
30
|
+
1. **Understand** the user's request (contract type, features, network)
|
|
31
|
+
2. **Search** knowledge base for relevant patterns and examples
|
|
32
|
+
3. **Generate** code based on templates and best practices
|
|
33
|
+
4. **Review** security patterns and apply fixes
|
|
34
|
+
5. **Provide** deployment instructions
|
|
35
|
+
|
|
36
|
+
## Examples
|
|
37
|
+
|
|
38
|
+
- "Create a SIP-010 token called MOON with 1M supply"
|
|
39
|
+
- "Build an NFT collection with royalties"
|
|
40
|
+
- "How do I swap tokens on Velar?"
|
|
41
|
+
- "Deploy my contract to testnet"
|
|
42
|
+
|
|
43
|
+
## Resources
|
|
44
|
+
|
|
45
|
+
- Docs: https://docs.stacks.co
|
|
46
|
+
- Explorer: https://explorer.hiro.so
|
|
47
|
+
- Clarinet: https://github.com/hirosystems/clarinet
|
|
48
|
+
|
|
49
|
+
## Version
|
|
50
|
+
1.0.0 - 170+ knowledge entries across 8 domains
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Stacks Agent - GitHub Copilot Prompt
|
|
2
|
+
|
|
3
|
+
AI-powered Stacks blockchain development intelligence.
|
|
4
|
+
|
|
5
|
+
## Use with @stacks-agent
|
|
6
|
+
|
|
7
|
+
This prompt enhances Copilot for Stacks blockchain development.
|
|
8
|
+
|
|
9
|
+
## What I Can Help With
|
|
10
|
+
|
|
11
|
+
- **Clarity Smart Contracts**: Generate, audit, deploy
|
|
12
|
+
- **Token Standards**: SIP-010 (FT), SIP-009 (NFT)
|
|
13
|
+
- **DeFi Protocols**: Alex, Velar, Bitflow, Zest, Boost
|
|
14
|
+
- **Security**: Vulnerability detection and fixes
|
|
15
|
+
- **Stacks.js**: Frontend integration
|
|
16
|
+
- **BNS**: Name system operations
|
|
17
|
+
- **Stacking**: PoX stacking and pools
|
|
18
|
+
- **Deployment**: Testnet/mainnet guides
|
|
19
|
+
|
|
20
|
+
## Knowledge Base
|
|
21
|
+
|
|
22
|
+
Access 170+ entries via search:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
python3 .shared/stacks-agent/scripts/search.py "<your-query>"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Add `--domain <name>` for specific domains:
|
|
29
|
+
- clarity, templates, security, defi, stacksjs, bns, stacking, deployment
|
|
30
|
+
|
|
31
|
+
## My Approach
|
|
32
|
+
|
|
33
|
+
When you ask about Stacks development, I will:
|
|
34
|
+
|
|
35
|
+
1. **Search** relevant knowledge base entries
|
|
36
|
+
2. **Generate** code following best practices
|
|
37
|
+
3. **Apply** security patterns automatically
|
|
38
|
+
4. **Provide** deployment instructions
|
|
39
|
+
5. **Reference** official documentation
|
|
40
|
+
|
|
41
|
+
## Security First
|
|
42
|
+
|
|
43
|
+
All generated code includes:
|
|
44
|
+
- ✓ Access control (tx-sender checks)
|
|
45
|
+
- ✓ Error handling (try!/unwrap!)
|
|
46
|
+
- ✓ Input validation (asserts!)
|
|
47
|
+
- ✓ Named error constants
|
|
48
|
+
- ✓ Kebab-case naming
|
|
49
|
+
- ✓ Network compatibility
|
|
50
|
+
|
|
51
|
+
## Example Requests
|
|
52
|
+
|
|
53
|
+
"Create a meme token with 1B supply"
|
|
54
|
+
"Build an NFT marketplace contract"
|
|
55
|
+
"How to swap on Alex DEX?"
|
|
56
|
+
"Deploy to Stacks testnet"
|
|
57
|
+
"Audit this Clarity contract for security issues"
|
|
58
|
+
|
|
59
|
+
## Networks
|
|
60
|
+
|
|
61
|
+
- **Mainnet**: Production (SP... addresses)
|
|
62
|
+
- **Testnet**: Testing (ST... addresses, free STX)
|
|
63
|
+
- **Devnet**: Local development (Clarinet)
|
|
64
|
+
|
|
65
|
+
## Standards
|
|
66
|
+
|
|
67
|
+
- SIP-010 Trait: `SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard`
|
|
68
|
+
- SIP-009 Trait: `SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait`
|
|
69
|
+
|
|
70
|
+
## Resources
|
|
71
|
+
|
|
72
|
+
- Docs: https://docs.stacks.co
|
|
73
|
+
- Explorer: https://explorer.hiro.so
|
|
74
|
+
- Clarinet: https://github.com/hirosystems/clarinet
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
**Version**: 1.0.0
|
|
79
|
+
**Author**: kai-builder
|
|
80
|
+
**Knowledge Entries**: 170+
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Stacks Agent - Kiro Steering
|
|
2
|
+
|
|
3
|
+
Stacks blockchain development intelligence for Kiro AI.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Guide AI responses for Stacks blockchain development, Clarity smart contracts, and DeFi integration.
|
|
8
|
+
|
|
9
|
+
## Scope
|
|
10
|
+
|
|
11
|
+
- Clarity contract generation and auditing
|
|
12
|
+
- SIP-010 (fungible tokens) and SIP-009 (NFTs)
|
|
13
|
+
- DeFi protocols: Alex, Velar, Bitflow, Zest, Boost, Faktory
|
|
14
|
+
- Stacks.js frontend integration
|
|
15
|
+
- BNS (Bitcoin Name System)
|
|
16
|
+
- PoX stacking and delegation
|
|
17
|
+
- Deployment workflows
|
|
18
|
+
|
|
19
|
+
## Knowledge Access
|
|
20
|
+
|
|
21
|
+
Search knowledge base:
|
|
22
|
+
```bash
|
|
23
|
+
python3 .shared/stacks-agent/scripts/search.py "<query>" --domain <domain>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Domains: clarity, templates, security, defi, stacksjs, bns, stacking, deployment
|
|
27
|
+
|
|
28
|
+
## Response Guidelines
|
|
29
|
+
|
|
30
|
+
### For Contract Generation
|
|
31
|
+
1. Search templates domain for relevant patterns
|
|
32
|
+
2. Apply security patterns from security domain
|
|
33
|
+
3. Use kebab-case naming convention
|
|
34
|
+
4. Include error constants (ERR-*)
|
|
35
|
+
5. Add try!/unwrap! for error handling
|
|
36
|
+
6. Validate inputs with asserts!
|
|
37
|
+
|
|
38
|
+
### For DeFi Integration
|
|
39
|
+
1. Search defi domain for protocol specifics
|
|
40
|
+
2. Provide mainnet contract addresses
|
|
41
|
+
3. Include example function calls
|
|
42
|
+
4. Add Stacks.js integration if needed
|
|
43
|
+
|
|
44
|
+
### For Deployment
|
|
45
|
+
1. Search deployment domain for steps
|
|
46
|
+
2. Distinguish testnet vs mainnet
|
|
47
|
+
3. Include faucet links for testnet
|
|
48
|
+
4. Provide verification instructions
|
|
49
|
+
|
|
50
|
+
## Security Emphasis
|
|
51
|
+
|
|
52
|
+
Always check generated code for:
|
|
53
|
+
- Missing tx-sender validation
|
|
54
|
+
- Unchecked transfer returns
|
|
55
|
+
- Missing input validation
|
|
56
|
+
- Wrong network trait addresses
|
|
57
|
+
- Hardcoded magic numbers
|
|
58
|
+
|
|
59
|
+
## Code Style
|
|
60
|
+
|
|
61
|
+
```clarity
|
|
62
|
+
;; Good
|
|
63
|
+
(define-constant ERR-UNAUTHORIZED (err u100))
|
|
64
|
+
(define-public (transfer (amount uint))
|
|
65
|
+
(begin
|
|
66
|
+
(asserts! (> amount u0) ERR-INVALID-AMOUNT)
|
|
67
|
+
(try! (ft-transfer? token amount tx-sender recipient))
|
|
68
|
+
(ok true)))
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Networks
|
|
72
|
+
|
|
73
|
+
- Mainnet: SP... (production)
|
|
74
|
+
- Testnet: ST... (testing)
|
|
75
|
+
- Devnet: local (Clarinet)
|
|
76
|
+
|
|
77
|
+
## Version
|
|
78
|
+
1.0.0 - 170+ knowledge entries
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
id,category,name,description,code,contract,notes
|
|
2
|
+
1,resolve,name-to-address,"Resolve BNS name to address","(contract-call? .bns name-resolve namespace name)","SP000000000000000000002Q6VF78.bns","Returns principal of name owner"
|
|
3
|
+
2,resolve,address-to-name,"Get primary name for address","(contract-call? .bns resolve-principal address)","SP000000000000000000002Q6VF78.bns","Returns primary BNS name"
|
|
4
|
+
3,register,register-name,"Register a new BNS name","(contract-call? .bns-v2 name-register namespace name salt zonefile-hash)","BNS-V2 contract","Requires STX payment based on name length"
|
|
5
|
+
4,transfer,transfer-name,"Transfer BNS name ownership","(contract-call? .bns-v2 name-transfer namespace name new-owner zonefile-hash)","BNS-V2 contract","Owner only can transfer names"
|
|
6
|
+
5,update,update-zonefile,"Update name zonefile hash","(contract-call? .bns-v2 name-update namespace name zonefile-hash)","BNS-V2 contract","Updates DNS records for name"
|
|
7
|
+
6,lookup,name-info,"Get name details","(contract-call? .bns name-resolve namespace name)","SP000000000000000000002Q6VF78.bns","Returns owner zonefile-hash lease-ending-at"
|
|
8
|
+
7,lookup,get-namespace-price,"Get registration price","(contract-call? .bns-v2 get-namespace-price namespace)","BNS-V2 contract","Price in microSTX"
|
|
9
|
+
8,lookup,can-name-be-registered,"Check name availability","(contract-call? .bns-v2 can-name-be-registered namespace name)","BNS-V2 contract","Returns true if available"
|
|
10
|
+
9,bulk,batch-register,"Register multiple names","(map register-single-name names)","Custom contract","Loop through list of names"
|
|
11
|
+
10,renew,renew-name,"Renew name registration","(contract-call? .bns-v2 name-renewal namespace name)","BNS-V2 contract","Extends lease period"
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
id,category,name,syntax,description,example,notes
|
|
2
|
+
1,types,uint,"uint","Unsigned integer (0 to 2^128-1)","(define-data-var counter uint u0)","Use u prefix for literals"
|
|
3
|
+
2,types,int,"int","Signed integer (-2^127 to 2^127-1)","(define-data-var balance int 0)","Can be negative"
|
|
4
|
+
3,types,bool,"bool","Boolean true/false","(define-data-var active bool true)","true or false only"
|
|
5
|
+
4,types,principal,"principal","Stacks address or contract","tx-sender","SP... or ST... format"
|
|
6
|
+
5,types,buff,"(buff n)","Fixed-length byte buffer","(buff 32)","Max 1MB"
|
|
7
|
+
6,types,string-ascii,"(string-ascii n)","ASCII string","(string-ascii 50)","ASCII chars only"
|
|
8
|
+
7,types,string-utf8,"(string-utf8 n)","UTF-8 string","(string-utf8 100)","Unicode support"
|
|
9
|
+
8,types,list,"(list n type)","Fixed-length list","(list 10 uint)","Homogeneous types"
|
|
10
|
+
9,types,tuple,"{ key: type }","Named fields","{ name: (string-ascii 50), age: uint }","Like struct"
|
|
11
|
+
10,types,optional,"(optional type)","Maybe value","(optional uint)","some/none"
|
|
12
|
+
11,types,response,"(response ok-type err-type)","Result type","(response bool uint)","ok/err"
|
|
13
|
+
12,functions,define-public,"(define-public (name (arg type)) body)","Public function","(define-public (transfer (amount uint)) (ok true))","Callable externally"
|
|
14
|
+
13,functions,define-read-only,"(define-read-only (name) body)","Read-only function","(define-read-only (get-balance) (ok u100))","No state changes"
|
|
15
|
+
14,functions,define-private,"(define-private (name) body)","Private function","(define-private (helper) u1)","Internal only"
|
|
16
|
+
15,functions,define-data-var,"(define-data-var name type value)","State variable","(define-data-var owner principal tx-sender)","Mutable storage"
|
|
17
|
+
16,functions,define-map,"(define-map name key-type value-type)","Key-value map","(define-map balances principal uint)","Persistent storage"
|
|
18
|
+
17,functions,define-constant,"(define-constant name value)","Constant value","(define-constant ERR-UNAUTHORIZED (err u401))","Immutable"
|
|
19
|
+
18,functions,define-fungible-token,"(define-fungible-token name supply?)","Create FT","(define-fungible-token MY-TOKEN u1000000)","SIP-010 base"
|
|
20
|
+
19,functions,define-non-fungible-token,"(define-non-fungible-token name type)","Create NFT","(define-non-fungible-token MY-NFT uint)","SIP-009 base"
|
|
21
|
+
20,control,if,"(if condition then else)","Conditional","(if (> x u0) u1 u0)","Both branches required"
|
|
22
|
+
21,control,match,"(match opt (some val) expr none-expr)","Pattern match","(match (get-user) user (ok user) (err u404))","Optional/response"
|
|
23
|
+
22,control,let,"(let ((var val)) body)","Local binding","(let ((x u1) (y u2)) (+ x y))","Scoped variables"
|
|
24
|
+
23,control,begin,"(begin expr1 expr2 ...)","Sequence","(begin (print ""hi"") (ok true))","Returns last"
|
|
25
|
+
24,control,asserts!,"(asserts! condition error)","Assert or abort","(asserts! (is-eq tx-sender owner) ERR-UNAUTHORIZED)","Stops execution"
|
|
26
|
+
25,control,try!,"(try! response)","Unwrap or propagate","(try! (ft-transfer? token u100 from to))","Early return on err"
|
|
27
|
+
26,control,unwrap!,"(unwrap! opt error)","Unwrap or error","(unwrap! (map-get? users id) ERR-NOT-FOUND)","Must succeed"
|
|
28
|
+
27,control,unwrap-panic,"(unwrap-panic opt)","Unwrap or panic","(unwrap-panic (some u1))","Use carefully"
|
|
29
|
+
28,arithmetic,+,"(+ a b ...)","Addition","(+ u1 u2 u3)","Auto-checks overflow"
|
|
30
|
+
29,arithmetic,-,"(- a b)","Subtraction","(- u10 u5)","Returns uint if uint"
|
|
31
|
+
30,arithmetic,*,"(* a b ...)","Multiplication","(* u5 u3)","Auto-checks overflow"
|
|
32
|
+
31,arithmetic,/,"(/ a b)","Division","(/ u10 u2)","Integer division"
|
|
33
|
+
32,arithmetic,mod,"(mod a b)","Modulo","(mod u10 u3)","Remainder"
|
|
34
|
+
33,comparison,is-eq,"(is-eq a b)","Equality check","(is-eq tx-sender owner)","Works with all types"
|
|
35
|
+
34,comparison,>,"(> a b)","Greater than","(> u5 u3)","true or false"
|
|
36
|
+
35,comparison,<,"(< a b)","Less than","(< u3 u5)","true or false"
|
|
37
|
+
36,comparison,>=,"(>= a b)","Greater than or equal","(>= u5 u5)","true or false"
|
|
38
|
+
37,comparison,<=,"(<= a b)","Less than or equal","(<= u3 u5)","true or false"
|
|
39
|
+
38,logic,and,"(and expr1 expr2 ...)","Logical AND","(and (> x u0) (< x u100))","Short-circuits"
|
|
40
|
+
39,logic,or,"(or expr1 expr2 ...)","Logical OR","(or (is-eq x u1) (is-eq x u2))","Short-circuits"
|
|
41
|
+
40,logic,not,"(not expr)","Logical NOT","(not (is-eq x u0))","Inverts boolean"
|
|
42
|
+
41,map-functions,map-set,"(map-set map key value)","Set map entry","(map-set balances user u100)","Creates or updates"
|
|
43
|
+
42,map-functions,map-get?,"(map-get? map key)","Get map value","(map-get? balances user)","Returns optional"
|
|
44
|
+
43,map-functions,map-delete,"(map-delete map key)","Delete map entry","(map-delete balances user)","Removes key"
|
|
45
|
+
44,map-functions,map-insert,"(map-insert map key value)","Insert if not exists","(map-insert balances user u100)","False if exists"
|
|
46
|
+
45,var-functions,var-get,"(var-get var)","Get variable value","(var-get counter)","Returns current value"
|
|
47
|
+
46,var-functions,var-set,"(var-set var value)","Set variable value","(var-set counter u10)","Updates value"
|
|
48
|
+
47,token-functions,ft-transfer?,"(ft-transfer? token amount from to)","Transfer fungible tokens","(ft-transfer? my-token u100 tx-sender recipient)","Returns response"
|
|
49
|
+
48,token-functions,ft-mint?,"(ft-mint? token amount recipient)","Mint fungible tokens","(ft-mint? my-token u1000 recipient)","Increases supply"
|
|
50
|
+
49,token-functions,ft-burn?,"(ft-burn? token amount sender)","Burn fungible tokens","(ft-burn? my-token u100 tx-sender)","Decreases supply"
|
|
51
|
+
50,token-functions,ft-get-balance,"(ft-get-balance token principal)","Get FT balance","(ft-get-balance my-token user)","Returns uint"
|
|
52
|
+
51,token-functions,ft-get-supply,"(ft-get-supply token)","Get total supply","(ft-get-supply my-token)","Returns uint"
|
|
53
|
+
52,token-functions,nft-transfer?,"(nft-transfer? nft id from to)","Transfer NFT","(nft-transfer? my-nft u1 tx-sender recipient)","Returns response"
|
|
54
|
+
53,token-functions,nft-mint?,"(nft-mint? nft id recipient)","Mint NFT","(nft-mint? my-nft u1 recipient)","Returns response"
|
|
55
|
+
54,token-functions,nft-burn?,"(nft-burn? nft id sender)","Burn NFT","(nft-burn? my-nft u1 tx-sender)","Returns response"
|
|
56
|
+
55,token-functions,nft-get-owner?,"(nft-get-owner? nft id)","Get NFT owner","(nft-get-owner? my-nft u1)","Returns optional principal"
|
|
57
|
+
56,stx-functions,stx-transfer?,"(stx-transfer? amount from to)","Transfer STX","(stx-transfer? u1000000 tx-sender recipient)","Amount in microSTX"
|
|
58
|
+
57,stx-functions,stx-burn?,"(stx-burn? amount sender)","Burn STX","(stx-burn? u1000000 tx-sender)","Destroys STX"
|
|
59
|
+
58,stx-functions,stx-get-balance,"(stx-get-balance principal)","Get STX balance","(stx-get-balance tx-sender)","Returns uint"
|
|
60
|
+
59,contract-functions,contract-call?,"(contract-call? contract function args...)","Call external contract","(contract-call? .other-contract transfer u100)","Returns response"
|
|
61
|
+
60,contract-functions,as-contract,"(as-contract expr)","Execute as contract","(as-contract (stx-transfer? u100 tx-sender recipient))","Contract is tx-sender"
|
|
62
|
+
61,contract-functions,contract-of,"(contract-of trait-ref)","Get contract principal","(contract-of .token-trait)","Returns principal"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
id,category,name,description,traits,use_case,features
|
|
2
|
+
1,token,sip010-basic,"Basic SIP-010 fungible token","SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard","Meme tokens utility tokens","transfer get-name get-symbol get-decimals get-balance get-total-supply get-token-uri"
|
|
3
|
+
2,token,sip010-mintable,"SIP-010 with mint function","sip-010-trait","Reward tokens inflationary","All SIP-010 functions plus mint (owner-only)"
|
|
4
|
+
3,token,sip010-burnable,"SIP-010 with burn on transfer","sip-010-trait","Deflationary tokens","All SIP-010 functions plus burn mechanism"
|
|
5
|
+
4,token,sip010-capped,"SIP-010 with max supply cap","sip-010-trait","Limited supply tokens","All SIP-010 functions with supply cap check"
|
|
6
|
+
5,nft,sip009-basic,"Basic SIP-009 NFT collection","SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait","PFP collections","transfer get-last-token-id get-token-uri get-owner"
|
|
7
|
+
6,nft,sip009-mintable,"SIP-009 with public mint","nft-trait","Open mints allowlists","All SIP-009 functions plus public mint"
|
|
8
|
+
7,nft,sip009-royalties,"SIP-009 with royalty support","nft-trait","Creator royalties","All SIP-009 functions plus royalty tracking"
|
|
9
|
+
8,defi,vault-basic,"Simple STX vault","none","Savings staking","deposit withdraw get-balance"
|
|
10
|
+
9,defi,vault-timelocked,"Vault with unlock period","none","Vesting lockups","deposit withdraw-after-period get-unlock-time"
|
|
11
|
+
10,defi,pool-basic,"Basic liquidity pool","none","DEX pools","add-liquidity remove-liquidity swap get-reserves"
|
|
12
|
+
11,dao,dao-basic,"Simple DAO with proposals","none","Governance","create-proposal vote execute-proposal"
|
|
13
|
+
12,dao,dao-treasury,"DAO with treasury management","none","Protocol governance","All DAO functions plus treasury management"
|
|
14
|
+
13,marketplace,nft-marketplace,"NFT listing and sales","nft-trait","NFT trading","list-nft unlist-nft buy-nft get-listing"
|
|
15
|
+
14,stacking,stacking-pool,"Stacking pool delegation","none","Pool operators","delegate revoke get-delegation-info claim-rewards"
|