@dex-ai/coding-extensions 0.2.4
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/README.md +64 -0
- package/package.json +42 -0
- package/skills/code-review/SKILL.md +160 -0
- package/skills/debug-investigate/SKILL.md +151 -0
- package/skills/extension-dev/SKILL.md +177 -0
- package/skills/git-workflow/SKILL.md +167 -0
- package/skills/retrospective/SKILL.md +194 -0
- package/skills/skill-creator/SKILL.md +145 -0
- package/skills/spec-design/SKILL.md +228 -0
- package/skills/spec-impl/SKILL.md +265 -0
- package/src/index.ts +171 -0
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# dex-ai-coding-extensions
|
|
2
|
+
|
|
3
|
+
Coding workflow skills for [Dex](https://github.com/klxdev/dex-ai-coding-agent) — structured methodologies for specification, implementation, retrospectives, and more.
|
|
4
|
+
|
|
5
|
+
## Skills
|
|
6
|
+
|
|
7
|
+
| Skill | Description |
|
|
8
|
+
|-------|-------------|
|
|
9
|
+
| `spec-design-tasks` | Idea → RFC spec → technical design → task breakdown |
|
|
10
|
+
| `spec-implementation` | Phased implementation: review → explore → plan → test → code → verify |
|
|
11
|
+
| `retrospective` | Post-session learning extraction into Dex's memory system |
|
|
12
|
+
| `skill-creator` | Create and manage Dex skills with proper structure |
|
|
13
|
+
| `git-workflow` | Multi-repo git coordination patterns |
|
|
14
|
+
| `debug-investigate` | Structured debugging and root-cause analysis |
|
|
15
|
+
| `code-review` | Structured code review with quality checks |
|
|
16
|
+
| `extension-dev` | Dex extension development patterns |
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { codingExtensions } from '@dex-ai/coding-extensions';
|
|
22
|
+
|
|
23
|
+
const agent = await Agent.create({
|
|
24
|
+
extensions: [codingExtensions(), ...otherExtensions],
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Load a subset:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
codingExtensions({ include: ['spec-implementation', 'debug-investigate'] })
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Exclude specific skills:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
codingExtensions({ exclude: ['extension-dev'] })
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Structure
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
src/index.ts # Single extension that loads all skills
|
|
44
|
+
skills/
|
|
45
|
+
├── spec-design/ # SKILL.md — spec & design workflow
|
|
46
|
+
├── spec-impl/ # SKILL.md — implementation phases
|
|
47
|
+
├── retrospective/ # SKILL.md — memory-based retrospectives
|
|
48
|
+
├── skill-creator/ # SKILL.md — meta-skill for creating skills
|
|
49
|
+
├── git-workflow/ # SKILL.md — multi-repo git patterns
|
|
50
|
+
├── debug-investigate/# SKILL.md — structured debugging
|
|
51
|
+
├── code-review/ # SKILL.md — code review checklist
|
|
52
|
+
└── extension-dev/ # SKILL.md — Dex extension patterns
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Development
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
bun install
|
|
59
|
+
bun run typecheck
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dex-ai/coding-extensions",
|
|
3
|
+
"version": "0.2.4",
|
|
4
|
+
"description": "Coding workflow skills for Dex — spec design, implementation, retrospectives, debugging, code review, and more.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./src/index.ts",
|
|
9
|
+
"default": "./src/index.ts"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"src",
|
|
14
|
+
"skills"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"typecheck": "tsc --noEmit",
|
|
18
|
+
"test": "bun test",
|
|
19
|
+
"changeset": "changeset",
|
|
20
|
+
"version": "changeset version",
|
|
21
|
+
"release": "changeset publish"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@dex-ai/sdk": "^0.1.2"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "^5.6.3",
|
|
28
|
+
"@types/bun": "latest",
|
|
29
|
+
"@changesets/cli": "^2.29.0"
|
|
30
|
+
},
|
|
31
|
+
"resolutions": {
|
|
32
|
+
"@dex-ai/sdk": "file:../dex-ai-sdk"
|
|
33
|
+
},
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"engines": {
|
|
36
|
+
"bun": ">=1.1.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"registry": "https://registry.npmjs.org/"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-review
|
|
3
|
+
description: Structured code review — checks for correctness, edge cases, error handling, performance, style consistency, and test coverage. Produces actionable feedback with specific file/line references.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## What I do
|
|
7
|
+
|
|
8
|
+
- Review code changes for correctness, safety, and quality
|
|
9
|
+
- Check error handling, edge cases, and boundary conditions
|
|
10
|
+
- Verify style consistency with the existing codebase
|
|
11
|
+
- Assess test coverage for new/modified code
|
|
12
|
+
- Use LSP diagnostics and type checking as part of review
|
|
13
|
+
- Produce actionable feedback with specific locations and suggestions
|
|
14
|
+
|
|
15
|
+
## When to use me
|
|
16
|
+
|
|
17
|
+
Use this skill when:
|
|
18
|
+
- Reviewing your own code before committing
|
|
19
|
+
- The user asks for a code review
|
|
20
|
+
- Validating changes made during an implementation
|
|
21
|
+
- Checking code quality after a refactor
|
|
22
|
+
|
|
23
|
+
## Core Principles
|
|
24
|
+
|
|
25
|
+
### Actionable Feedback
|
|
26
|
+
Every comment should be specific and actionable. Not "this could be better" but "line 42: this catch swallows the error — rethrow or log it."
|
|
27
|
+
|
|
28
|
+
### Severity Levels
|
|
29
|
+
Categorize findings:
|
|
30
|
+
- 🔴 **Critical** — Bugs, security issues, data loss risks
|
|
31
|
+
- 🟡 **Warning** — Edge cases, missing error handling, potential issues
|
|
32
|
+
- 🔵 **Suggestion** — Style improvements, readability, minor optimizations
|
|
33
|
+
- ✅ **Good** — Things done well (positive reinforcement)
|
|
34
|
+
|
|
35
|
+
### Context-Aware
|
|
36
|
+
Check findings against the project's actual patterns. Don't flag something as wrong if the codebase consistently does it that way.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Review Workflow
|
|
41
|
+
|
|
42
|
+
### Step 1: Identify Scope
|
|
43
|
+
|
|
44
|
+
Determine what to review:
|
|
45
|
+
- `git diff --stat` — See changed files
|
|
46
|
+
- `git diff` — See actual changes
|
|
47
|
+
- Or review specific files the user points to
|
|
48
|
+
|
|
49
|
+
### Step 2: Understand Context
|
|
50
|
+
|
|
51
|
+
Before reviewing:
|
|
52
|
+
1. Understand the purpose of the change (feature, fix, refactor?)
|
|
53
|
+
2. Read related code to understand the bigger picture
|
|
54
|
+
3. Check for related tests
|
|
55
|
+
4. Use `memory_recall_facts` for relevant project conventions
|
|
56
|
+
|
|
57
|
+
### Step 3: Automated Checks
|
|
58
|
+
|
|
59
|
+
Run automated quality gates:
|
|
60
|
+
1. **LSP diagnostics** — `lsp_diagnostics` on modified files
|
|
61
|
+
2. **Type safety** — Look for `any` types, unsafe casts, missing null checks
|
|
62
|
+
3. **AST patterns** — Use `ast_grep_search` to check for known anti-patterns
|
|
63
|
+
|
|
64
|
+
### Step 4: Manual Review
|
|
65
|
+
|
|
66
|
+
Check each file for:
|
|
67
|
+
|
|
68
|
+
#### Correctness
|
|
69
|
+
- Does the logic do what it's supposed to?
|
|
70
|
+
- Are all code paths handled?
|
|
71
|
+
- Are assumptions documented or validated?
|
|
72
|
+
- Do variable names accurately reflect their purpose?
|
|
73
|
+
|
|
74
|
+
#### Error Handling
|
|
75
|
+
- Are errors caught at appropriate boundaries?
|
|
76
|
+
- Are caught errors handled (not swallowed)?
|
|
77
|
+
- Are error messages informative?
|
|
78
|
+
- Can the caller distinguish error types?
|
|
79
|
+
|
|
80
|
+
#### Edge Cases
|
|
81
|
+
- Empty inputs, null/undefined values
|
|
82
|
+
- Boundary conditions (off-by-one, max values)
|
|
83
|
+
- Concurrent access or race conditions
|
|
84
|
+
- Network failures, timeouts
|
|
85
|
+
|
|
86
|
+
#### Performance
|
|
87
|
+
- Unnecessary allocations in loops
|
|
88
|
+
- O(n²) where O(n) is possible
|
|
89
|
+
- Missing early returns
|
|
90
|
+
- Unnecessary awaits or blocking
|
|
91
|
+
|
|
92
|
+
#### Security
|
|
93
|
+
- Input validation on external data
|
|
94
|
+
- No secrets in code
|
|
95
|
+
- Proper sanitization
|
|
96
|
+
- Authorization checks where needed
|
|
97
|
+
|
|
98
|
+
#### Style & Consistency
|
|
99
|
+
- Matches existing codebase patterns
|
|
100
|
+
- Naming conventions followed
|
|
101
|
+
- Import ordering consistent
|
|
102
|
+
- No dead code or commented-out blocks
|
|
103
|
+
|
|
104
|
+
#### Tests
|
|
105
|
+
- New functionality has tests
|
|
106
|
+
- Edge cases tested
|
|
107
|
+
- Error paths tested
|
|
108
|
+
- Existing tests still relevant
|
|
109
|
+
|
|
110
|
+
### Step 5: Produce Report
|
|
111
|
+
|
|
112
|
+
Format findings as:
|
|
113
|
+
|
|
114
|
+
```markdown
|
|
115
|
+
## Code Review: [Description]
|
|
116
|
+
|
|
117
|
+
### Summary
|
|
118
|
+
[One-paragraph overview of the change and overall assessment]
|
|
119
|
+
|
|
120
|
+
### Findings
|
|
121
|
+
|
|
122
|
+
#### 🔴 Critical
|
|
123
|
+
1. **`path/to/file.ts:42`** — [Description]
|
|
124
|
+
```typescript
|
|
125
|
+
// Current
|
|
126
|
+
} catch (e) {}
|
|
127
|
+
// Suggested
|
|
128
|
+
} catch (e) { throw new AppError('context', { cause: e }); }
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### 🟡 Warning
|
|
132
|
+
1. **`path/to/file.ts:67`** — [Description]
|
|
133
|
+
- Suggestion: [What to do]
|
|
134
|
+
|
|
135
|
+
#### 🔵 Suggestion
|
|
136
|
+
1. **`path/to/file.ts:15`** — [Description]
|
|
137
|
+
|
|
138
|
+
#### ✅ Good
|
|
139
|
+
1. **`path/to/file.ts:30-45`** — [What's done well]
|
|
140
|
+
|
|
141
|
+
### Verdict
|
|
142
|
+
- [ ] Ready to merge
|
|
143
|
+
- [ ] Needs changes (see critical/warnings)
|
|
144
|
+
- [ ] Needs discussion
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Common Anti-Patterns to Flag
|
|
150
|
+
|
|
151
|
+
- `catch {}` or `catch (_) {}` — swallowed errors
|
|
152
|
+
- `as any` or `as unknown as T` — unsafe type coercion
|
|
153
|
+
- `// TODO` without tracking — lost intent
|
|
154
|
+
- `console.log` left in production code
|
|
155
|
+
- Missing `await` on async calls
|
|
156
|
+
- Mutable shared state without synchronization
|
|
157
|
+
- Magic numbers without named constants
|
|
158
|
+
- Functions over 50 lines without clear reason
|
|
159
|
+
- Deeply nested conditionals (>3 levels)
|
|
160
|
+
- String concatenation for error messages (use template literals)
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: debug-investigate
|
|
3
|
+
description: Structured debugging and root-cause analysis — reproduce, hypothesize, investigate, fix, verify. Uses AST search, LSP navigation, and memory to systematically diagnose issues.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## What I do
|
|
7
|
+
|
|
8
|
+
- Systematically diagnose bugs and unexpected behavior
|
|
9
|
+
- Form and test hypotheses using code analysis tools
|
|
10
|
+
- Trace execution paths to find root causes
|
|
11
|
+
- Propose minimal fixes that address the root cause (not symptoms)
|
|
12
|
+
- Store debugging patterns in memory for future reference
|
|
13
|
+
|
|
14
|
+
## When to use me
|
|
15
|
+
|
|
16
|
+
Use this skill when:
|
|
17
|
+
- Something isn't working and the cause isn't obvious
|
|
18
|
+
- An error message needs investigation
|
|
19
|
+
- A test is failing unexpectedly
|
|
20
|
+
- Behavior doesn't match expectations
|
|
21
|
+
- Performance issues need diagnosis
|
|
22
|
+
|
|
23
|
+
## Core Principles
|
|
24
|
+
|
|
25
|
+
### Reproduce First
|
|
26
|
+
Never guess at fixes without understanding the problem. Reproduce the issue or at minimum understand the exact symptoms.
|
|
27
|
+
|
|
28
|
+
### Hypothesize, Don't Grep Randomly
|
|
29
|
+
Form specific hypotheses about what could cause the behavior, then test each one. Don't just search the codebase randomly hoping to stumble on the answer.
|
|
30
|
+
|
|
31
|
+
### Root Cause, Not Symptoms
|
|
32
|
+
Fix the underlying cause. If a null check would "fix" the crash, ask WHY the value is null in the first place.
|
|
33
|
+
|
|
34
|
+
### Minimal Fix
|
|
35
|
+
Change as little as possible. The fix should be proportional to the bug.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Debugging Workflow
|
|
40
|
+
|
|
41
|
+
### Phase 1: Understand the Symptoms
|
|
42
|
+
|
|
43
|
+
1. **Collect information:**
|
|
44
|
+
- What is the exact error message or unexpected behavior?
|
|
45
|
+
- What is the expected behavior?
|
|
46
|
+
- When did it start happening? (recent change?)
|
|
47
|
+
- Is it consistent or intermittent?
|
|
48
|
+
|
|
49
|
+
2. **Reproduce (if possible):**
|
|
50
|
+
- Run the failing command/test
|
|
51
|
+
- Note the exact output
|
|
52
|
+
- Identify the entry point
|
|
53
|
+
|
|
54
|
+
### Phase 2: Form Hypotheses
|
|
55
|
+
|
|
56
|
+
Based on the symptoms, generate 2-4 specific hypotheses:
|
|
57
|
+
|
|
58
|
+
```markdown
|
|
59
|
+
## Hypotheses
|
|
60
|
+
|
|
61
|
+
1. **[Most likely]**: [Description of what might be wrong]
|
|
62
|
+
- Evidence for: [What supports this]
|
|
63
|
+
- How to test: [What to look at]
|
|
64
|
+
|
|
65
|
+
2. **[Alternative]**: [Description]
|
|
66
|
+
- Evidence for: [What supports this]
|
|
67
|
+
- How to test: [What to look at]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Prioritize hypotheses by:
|
|
71
|
+
- Recent changes (most bugs come from recent code)
|
|
72
|
+
- Simplest explanation (Occam's razor)
|
|
73
|
+
- Matching error patterns
|
|
74
|
+
|
|
75
|
+
### Phase 3: Investigate
|
|
76
|
+
|
|
77
|
+
Test each hypothesis systematically:
|
|
78
|
+
|
|
79
|
+
1. **Trace the code path** — Use `lsp_navigation` (definition, references, call hierarchy) to follow execution
|
|
80
|
+
2. **Search for patterns** — Use `ast_grep_search` to find related code
|
|
81
|
+
3. **Check types** — Use `lsp_diagnostics` and hover for type information
|
|
82
|
+
4. **Read relevant code** — Read the actual implementation, don't assume
|
|
83
|
+
5. **Check git history** — `git log --oneline -10 -- path/to/file` for recent changes
|
|
84
|
+
6. **Recall context** — `memory_recall_facts` for known issues or patterns
|
|
85
|
+
|
|
86
|
+
For each hypothesis, either:
|
|
87
|
+
- **Confirmed** — Found the root cause, move to Phase 4
|
|
88
|
+
- **Eliminated** — Evidence disproves this hypothesis, move to next
|
|
89
|
+
- **Needs more info** — Ask the user ONE specific question
|
|
90
|
+
|
|
91
|
+
### Phase 4: Root Cause Analysis
|
|
92
|
+
|
|
93
|
+
Once the root cause is found:
|
|
94
|
+
|
|
95
|
+
```markdown
|
|
96
|
+
## Root Cause
|
|
97
|
+
|
|
98
|
+
**What**: [One-sentence description of the bug]
|
|
99
|
+
**Where**: `path/to/file.ts:line` — [specific location]
|
|
100
|
+
**Why**: [Why this code produces the wrong behavior]
|
|
101
|
+
**When introduced**: [If identifiable — commit, PR, or "existing"]
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Phase 5: Fix
|
|
105
|
+
|
|
106
|
+
1. **Propose the fix** — Explain what needs to change and why
|
|
107
|
+
2. **Implement minimally** — Change only what's necessary
|
|
108
|
+
3. **Consider edge cases** — Does the fix handle related scenarios?
|
|
109
|
+
4. **Check for similar bugs** — Use `ast_grep_search` to find similar patterns that might have the same issue
|
|
110
|
+
|
|
111
|
+
### Phase 6: Verify
|
|
112
|
+
|
|
113
|
+
1. **Run the failing test/command** — Does it pass now?
|
|
114
|
+
2. **Run related tests** — No regressions?
|
|
115
|
+
3. **Run typecheck** — No type errors introduced?
|
|
116
|
+
4. **Run LSP diagnostics** — Clean on modified files?
|
|
117
|
+
|
|
118
|
+
### Phase 7: Learn
|
|
119
|
+
|
|
120
|
+
If the bug revealed a pattern worth remembering:
|
|
121
|
+
- Store the debugging pattern via `memory_remember_fact`
|
|
122
|
+
- If it's a multi-step diagnosis process, store as a procedure
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Common Debugging Patterns
|
|
127
|
+
|
|
128
|
+
### "It worked before"
|
|
129
|
+
→ Check `git log` for recent changes to the affected files
|
|
130
|
+
|
|
131
|
+
### "It works in isolation but fails in integration"
|
|
132
|
+
→ Look for shared state, import order issues, or missing initialization
|
|
133
|
+
|
|
134
|
+
### "The type says X but runtime shows Y"
|
|
135
|
+
→ Look for `as` casts, `any` types, or mismatched generics
|
|
136
|
+
|
|
137
|
+
### "It fails silently"
|
|
138
|
+
→ Look for swallowed errors: `catch {}`, `.catch(() => {})`, missing `await`
|
|
139
|
+
|
|
140
|
+
### "It works sometimes"
|
|
141
|
+
→ Race conditions, timing issues, or uninitialized state
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Anti-Patterns to Avoid
|
|
146
|
+
|
|
147
|
+
- **Shotgun debugging** — Making random changes hoping something works
|
|
148
|
+
- **Symptom fixing** — Adding null checks without understanding why null
|
|
149
|
+
- **Cargo cult fixes** — Copying solutions without understanding them
|
|
150
|
+
- **Over-fixing** — Rewriting the whole module when one line is wrong
|
|
151
|
+
- **Assuming without reading** — "I think this function does X" — read it
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: extension-dev
|
|
3
|
+
description: Dex extension development patterns — creating tools, skills, providers, and lifecycle hooks. Covers the SDK interfaces, wiring into the CLI, testing, and publishing.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## What I do
|
|
7
|
+
|
|
8
|
+
- Guide creation of new Dex extensions (tools, skills, providers, events)
|
|
9
|
+
- Explain SDK interfaces and patterns
|
|
10
|
+
- Show how to wire extensions into the CLI loader
|
|
11
|
+
- Cover testing patterns for extensions
|
|
12
|
+
- Guide publishing to Verdaccio
|
|
13
|
+
|
|
14
|
+
## When to use me
|
|
15
|
+
|
|
16
|
+
Use this skill when:
|
|
17
|
+
- Creating a new Dex extension from scratch
|
|
18
|
+
- Adding tools, skills, or providers to an existing extension
|
|
19
|
+
- Understanding how extensions are loaded and initialized
|
|
20
|
+
- Debugging extension lifecycle issues
|
|
21
|
+
- Publishing extension packages
|
|
22
|
+
|
|
23
|
+
## Extension Anatomy
|
|
24
|
+
|
|
25
|
+
An extension is an object conforming to the `Extension` interface:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import type { Extension, Tool, Skill } from "@dex-ai/sdk";
|
|
29
|
+
|
|
30
|
+
export function myExtension(): Extension {
|
|
31
|
+
return {
|
|
32
|
+
name: "my-extension",
|
|
33
|
+
|
|
34
|
+
// Tools the agent can call
|
|
35
|
+
tools: [/* Tool[] */],
|
|
36
|
+
|
|
37
|
+
// Skills injected into the system prompt
|
|
38
|
+
skills: [/* Skill[] */],
|
|
39
|
+
|
|
40
|
+
// Event handlers
|
|
41
|
+
on: {
|
|
42
|
+
agentStart(ctx) { /* ... */ },
|
|
43
|
+
agentEnd(ctx) { /* ... */ },
|
|
44
|
+
toolCall(ctx, call) { /* ... */ },
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
// Lifecycle
|
|
48
|
+
init(ctx) { /* async setup */ },
|
|
49
|
+
dispose() { /* cleanup */ },
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Creating a Tool
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { z } from "zod";
|
|
58
|
+
import type { Tool } from "@dex-ai/sdk";
|
|
59
|
+
|
|
60
|
+
const myTool: Tool = {
|
|
61
|
+
name: "my_tool",
|
|
62
|
+
description: "What the tool does — be specific for the LLM",
|
|
63
|
+
access: "read", // "read" = no side effects, "write" = modifies state
|
|
64
|
+
parameters: z.object({
|
|
65
|
+
input: z.string().describe("Description shown to the model"),
|
|
66
|
+
optional: z.number().optional().describe("Optional param"),
|
|
67
|
+
}),
|
|
68
|
+
execute(input, gctx) {
|
|
69
|
+
// input is already parsed & validated via zod
|
|
70
|
+
// gctx provides access to agent state, config, etc.
|
|
71
|
+
return { type: "text", value: "result" };
|
|
72
|
+
// or: { type: "error-text", value: "error message" }
|
|
73
|
+
// or: { type: "json", value: { key: "value" } }
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Tool Access Levels
|
|
79
|
+
- `"read"` — Safe, no side effects (search, read, inspect)
|
|
80
|
+
- `"write"` — Modifies state (edit files, run commands, git operations)
|
|
81
|
+
|
|
82
|
+
## Creating a Skill
|
|
83
|
+
|
|
84
|
+
A skill injects markdown instructions into the system prompt:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const skill: Skill = {
|
|
88
|
+
name: "my-skill",
|
|
89
|
+
description: "Short description for the catalog",
|
|
90
|
+
content: "## Instructions\n\nMarkdown content here...",
|
|
91
|
+
when: (actx) => true, // Optional: conditional activation
|
|
92
|
+
};
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Or load from a SKILL.md file:
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { readFileSync } from "node:fs";
|
|
99
|
+
import { join } from "node:path";
|
|
100
|
+
|
|
101
|
+
const raw = readFileSync(join(import.meta.dir, "..", "skills", "my-skill", "SKILL.md"), "utf-8");
|
|
102
|
+
const body = raw.replace(/^---[\s\S]*?---\s*/, ""); // strip frontmatter
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Extension Loading
|
|
106
|
+
|
|
107
|
+
Extensions are loaded in the CLI via `createCliExtensions()` in `dex-ai-coding-agent/packages/cli/bin/dex.ts`. The loader imports from:
|
|
108
|
+
- Built-in packages (always loaded)
|
|
109
|
+
- `~/.dex/extensions/` (global user extensions)
|
|
110
|
+
- `<project>/.dex/extensions/` (project-scoped)
|
|
111
|
+
|
|
112
|
+
To add a new built-in extension:
|
|
113
|
+
1. Create the package (or add to existing)
|
|
114
|
+
2. Add to the imports in `dex.ts`
|
|
115
|
+
3. Add to the extensions array
|
|
116
|
+
|
|
117
|
+
## State & Context
|
|
118
|
+
|
|
119
|
+
Extensions can use agent state for cross-extension communication:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
// In init or tool execute:
|
|
123
|
+
gctx.agent.state.set("my-key", value);
|
|
124
|
+
const val = gctx.agent.state.get("my-key");
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Testing Extensions
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { describe, it, expect } from "bun:test";
|
|
131
|
+
|
|
132
|
+
describe("my-tool", () => {
|
|
133
|
+
it("should return expected result", () => {
|
|
134
|
+
const tool = myTool;
|
|
135
|
+
const result = tool.execute({ input: "test" }, mockGctx);
|
|
136
|
+
expect(result).toEqual({ type: "text", value: "expected" });
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
For tools that need agent context, create a minimal mock:
|
|
142
|
+
```typescript
|
|
143
|
+
const mockGctx = {
|
|
144
|
+
agent: {
|
|
145
|
+
state: new Map(),
|
|
146
|
+
config: { /* minimal config */ },
|
|
147
|
+
},
|
|
148
|
+
} as any;
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Publishing
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Bump version
|
|
155
|
+
# Then publish to Verdaccio:
|
|
156
|
+
bun publish --registry http://localhost:4873
|
|
157
|
+
|
|
158
|
+
# Update consumers:
|
|
159
|
+
cd ../dex-ai-coding-agent
|
|
160
|
+
bun install
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Common Patterns
|
|
164
|
+
|
|
165
|
+
### Extension with both tools and skills
|
|
166
|
+
Most extensions provide both — tools for actions and skills for instructions on when/how to use them.
|
|
167
|
+
|
|
168
|
+
### Conditional skills
|
|
169
|
+
Use `when` to only inject a skill when relevant (e.g., only when certain files exist in the project).
|
|
170
|
+
|
|
171
|
+
### Extension options
|
|
172
|
+
Use a factory function pattern for configurable extensions:
|
|
173
|
+
```typescript
|
|
174
|
+
export function myExtension(opts: { verbose?: boolean } = {}): Extension {
|
|
175
|
+
return { name: "my-ext", tools: [/* use opts here */] };
|
|
176
|
+
}
|
|
177
|
+
```
|