antigravity-ai-kit 2.1.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/.agent/README.md +76 -0
- package/.agent/agents/README.md +129 -0
- package/.agent/agents/architect.md +184 -0
- package/.agent/agents/backend-specialist.md +77 -0
- package/.agent/agents/build-error-resolver.md +93 -0
- package/.agent/agents/code-reviewer.md +161 -0
- package/.agent/agents/database-architect.md +119 -0
- package/.agent/agents/devops-engineer.md +138 -0
- package/.agent/agents/doc-updater.md +79 -0
- package/.agent/agents/e2e-runner.md +110 -0
- package/.agent/agents/explorer-agent.md +135 -0
- package/.agent/agents/frontend-specialist.md +68 -0
- package/.agent/agents/knowledge-agent.md +83 -0
- package/.agent/agents/mobile-developer.md +114 -0
- package/.agent/agents/performance-optimizer.md +145 -0
- package/.agent/agents/planner.md +190 -0
- package/.agent/agents/refactor-cleaner.md +92 -0
- package/.agent/agents/reliability-engineer.md +98 -0
- package/.agent/agents/security-reviewer.md +145 -0
- package/.agent/agents/sprint-orchestrator.md +114 -0
- package/.agent/agents/tdd-guide.md +178 -0
- package/.agent/checklists/README.md +101 -0
- package/.agent/checklists/pre-commit.md +93 -0
- package/.agent/checklists/session-end.md +84 -0
- package/.agent/checklists/session-start.md +86 -0
- package/.agent/commands/README.md +119 -0
- package/.agent/commands/adr.md +29 -0
- package/.agent/commands/ask.md +28 -0
- package/.agent/commands/build.md +30 -0
- package/.agent/commands/changelog.md +40 -0
- package/.agent/commands/checkpoint.md +28 -0
- package/.agent/commands/code-review.md +64 -0
- package/.agent/commands/compact.md +28 -0
- package/.agent/commands/cook.md +30 -0
- package/.agent/commands/db.md +30 -0
- package/.agent/commands/debug.md +30 -0
- package/.agent/commands/deploy.md +36 -0
- package/.agent/commands/design.md +29 -0
- package/.agent/commands/doc.md +30 -0
- package/.agent/commands/eval.md +30 -0
- package/.agent/commands/fix.md +32 -0
- package/.agent/commands/git.md +32 -0
- package/.agent/commands/help.md +31 -0
- package/.agent/commands/implement.md +30 -0
- package/.agent/commands/integrate.md +32 -0
- package/.agent/commands/learn.md +29 -0
- package/.agent/commands/perf.md +31 -0
- package/.agent/commands/plan.md +55 -0
- package/.agent/commands/pr.md +30 -0
- package/.agent/commands/refactor.md +32 -0
- package/.agent/commands/research.md +28 -0
- package/.agent/commands/scout.md +30 -0
- package/.agent/commands/security-scan.md +33 -0
- package/.agent/commands/setup.md +31 -0
- package/.agent/commands/status.md +58 -0
- package/.agent/commands/tdd.md +72 -0
- package/.agent/commands/verify.md +58 -0
- package/.agent/decisions/001-trust-grade-governance.md +46 -0
- package/.agent/engine/loading-rules.json +98 -0
- package/.agent/engine/workflow-state.json +120 -0
- package/.agent/hooks/README.md +97 -0
- package/.agent/hooks/hooks.json +81 -0
- package/.agent/hooks/templates/session-end.md +110 -0
- package/.agent/hooks/templates/session-start.md +95 -0
- package/.agent/manifest.json +84 -0
- package/.agent/rules/coding-style.md +30 -0
- package/.agent/rules/git-workflow.md +45 -0
- package/.agent/rules/security.md +29 -0
- package/.agent/rules/testing.md +37 -0
- package/.agent/rules.md +272 -0
- package/.agent/session-context.md +80 -0
- package/.agent/session-state.json +27 -0
- package/.agent/skills/README.md +127 -0
- package/.agent/skills/api-patterns/SKILL.md +117 -0
- package/.agent/skills/app-builder/SKILL.md +202 -0
- package/.agent/skills/architecture/SKILL.md +109 -0
- package/.agent/skills/behavioral-modes/SKILL.md +295 -0
- package/.agent/skills/brainstorming/SKILL.md +156 -0
- package/.agent/skills/clean-code/SKILL.md +142 -0
- package/.agent/skills/context-budget/SKILL.md +78 -0
- package/.agent/skills/continuous-learning/SKILL.md +86 -0
- package/.agent/skills/database-design/SKILL.md +149 -0
- package/.agent/skills/debugging-strategies/SKILL.md +158 -0
- package/.agent/skills/deployment-procedures/SKILL.md +191 -0
- package/.agent/skills/docker-patterns/SKILL.md +161 -0
- package/.agent/skills/eval-harness/SKILL.md +89 -0
- package/.agent/skills/frontend-patterns/SKILL.md +141 -0
- package/.agent/skills/git-workflow/SKILL.md +159 -0
- package/.agent/skills/intelligent-routing/SKILL.md +180 -0
- package/.agent/skills/mobile-design/SKILL.md +191 -0
- package/.agent/skills/nodejs-patterns/SKILL.md +164 -0
- package/.agent/skills/parallel-agents/SKILL.md +200 -0
- package/.agent/skills/performance-profiling/SKILL.md +134 -0
- package/.agent/skills/plan-writing/SKILL.md +144 -0
- package/.agent/skills/security-practices/SKILL.md +140 -0
- package/.agent/skills/strategic-compact/SKILL.md +62 -0
- package/.agent/skills/testing-patterns/SKILL.md +141 -0
- package/.agent/skills/typescript-expert/SKILL.md +160 -0
- package/.agent/skills/verification-loop/SKILL.md +89 -0
- package/.agent/skills/webapp-testing/SKILL.md +175 -0
- package/.agent/workflows/README.md +78 -0
- package/.agent/workflows/brainstorm.md +100 -0
- package/.agent/workflows/create.md +75 -0
- package/.agent/workflows/debug.md +98 -0
- package/.agent/workflows/deploy.md +144 -0
- package/.agent/workflows/enhance.md +65 -0
- package/.agent/workflows/orchestrate.md +114 -0
- package/.agent/workflows/plan.md +72 -0
- package/.agent/workflows/preview.md +83 -0
- package/.agent/workflows/status.md +91 -0
- package/.agent/workflows/test.md +95 -0
- package/.agent/workflows/ui-ux-pro-max.md +127 -0
- package/LICENSE +21 -0
- package/README.md +585 -0
- package/bin/ag-kit.js +249 -0
- package/package.json +48 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: security-practices
|
|
3
|
+
description: Application security best practices and vulnerability prevention
|
|
4
|
+
triggers: [context, security, auth, vulnerability]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Security Practices Skill
|
|
8
|
+
|
|
9
|
+
> **Purpose**: Apply security best practices to protect applications
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
This skill provides security guidelines following OWASP standards and industry best practices.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Authentication
|
|
20
|
+
|
|
21
|
+
### Password Security
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// ✅ Use bcrypt with cost factor 12
|
|
25
|
+
import bcrypt from "bcrypt";
|
|
26
|
+
|
|
27
|
+
const SALT_ROUNDS = 12;
|
|
28
|
+
|
|
29
|
+
async function hashPassword(password: string): Promise<string> {
|
|
30
|
+
return bcrypt.hash(password, SALT_ROUNDS);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function verifyPassword(
|
|
34
|
+
password: string,
|
|
35
|
+
hash: string,
|
|
36
|
+
): Promise<boolean> {
|
|
37
|
+
return bcrypt.compare(password, hash);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### JWT Best Practices
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// Short-lived access tokens
|
|
45
|
+
const accessToken = jwt.sign(payload, SECRET, { expiresIn: "15m" });
|
|
46
|
+
|
|
47
|
+
// Longer-lived refresh tokens (stored securely)
|
|
48
|
+
const refreshToken = jwt.sign({ userId }, REFRESH_SECRET, { expiresIn: "7d" });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Input Validation
|
|
54
|
+
|
|
55
|
+
### Never Trust User Input
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// ❌ SQL Injection vulnerable
|
|
59
|
+
const query = `SELECT * FROM users WHERE id = ${userId}`;
|
|
60
|
+
|
|
61
|
+
// ✅ Parameterized query
|
|
62
|
+
const user = await prisma.user.findUnique({ where: { id: userId } });
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Sanitize Output
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
// ❌ XSS vulnerable
|
|
69
|
+
element.innerHTML = userInput;
|
|
70
|
+
|
|
71
|
+
// ✅ Escape HTML
|
|
72
|
+
import DOMPurify from "dompurify";
|
|
73
|
+
element.innerHTML = DOMPurify.sanitize(userInput);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## OWASP Top 10 Checklist
|
|
79
|
+
|
|
80
|
+
| Risk | Mitigation |
|
|
81
|
+
| :----------------------- | :----------------------------------- |
|
|
82
|
+
| **Injection** | Parameterized queries, ORMs |
|
|
83
|
+
| **Broken Auth** | Strong passwords, MFA, rate limiting |
|
|
84
|
+
| **Sensitive Data** | Encryption at rest/transit, HTTPS |
|
|
85
|
+
| **XXE** | Disable XML external entities |
|
|
86
|
+
| **Broken Access** | Verify permissions on every request |
|
|
87
|
+
| **Misconfig** | Security headers, remove defaults |
|
|
88
|
+
| **XSS** | Sanitize output, CSP headers |
|
|
89
|
+
| **Insecure Deserialize** | Validate input types |
|
|
90
|
+
| **Components** | Keep dependencies updated |
|
|
91
|
+
| **Logging** | Log security events, monitor |
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Security Headers
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
// Express/NestJS helmet middleware
|
|
99
|
+
app.use(helmet());
|
|
100
|
+
|
|
101
|
+
// Or manually:
|
|
102
|
+
res.setHeader("X-Content-Type-Options", "nosniff");
|
|
103
|
+
res.setHeader("X-Frame-Options", "DENY");
|
|
104
|
+
res.setHeader("X-XSS-Protection", "1; mode=block");
|
|
105
|
+
res.setHeader(
|
|
106
|
+
"Strict-Transport-Security",
|
|
107
|
+
"max-age=31536000; includeSubDomains",
|
|
108
|
+
);
|
|
109
|
+
res.setHeader("Content-Security-Policy", "default-src 'self'");
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Secrets Management
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# ❌ Never commit secrets
|
|
118
|
+
# .env file with API_KEY=sk-1234...
|
|
119
|
+
|
|
120
|
+
# ✅ Use environment variables
|
|
121
|
+
export API_KEY=$(vault read secret/api-key)
|
|
122
|
+
|
|
123
|
+
# ✅ Use secret managers
|
|
124
|
+
# AWS Secrets Manager, HashiCorp Vault, etc.
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Quick Reference
|
|
130
|
+
|
|
131
|
+
| Practice | Implementation |
|
|
132
|
+
| :----------- | :-------------------- |
|
|
133
|
+
| Passwords | bcrypt, Argon2 |
|
|
134
|
+
| Tokens | Short-lived JWT |
|
|
135
|
+
| SQL | Parameterized queries |
|
|
136
|
+
| XSS | Sanitize, CSP |
|
|
137
|
+
| HTTPS | TLS 1.3, HSTS |
|
|
138
|
+
| Secrets | Environment, vaults |
|
|
139
|
+
| Dependencies | npm audit, Snyk |
|
|
140
|
+
| Logging | Audit trail, no PII |
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: strategic-compact
|
|
3
|
+
description: Context window management with strategic compaction
|
|
4
|
+
triggers: [context-warning, manual]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Strategic Compact Skill
|
|
8
|
+
|
|
9
|
+
> **Purpose**: Manage context window efficiently while preserving important information
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
As conversations grow, context window limits require strategic compaction. This skill ensures important context is preserved while freeing space for new work.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Workflow
|
|
20
|
+
|
|
21
|
+
### 1. Assess Context
|
|
22
|
+
|
|
23
|
+
Evaluate current context usage:
|
|
24
|
+
|
|
25
|
+
- How much context is used?
|
|
26
|
+
- What is the oldest content?
|
|
27
|
+
- What is most important?
|
|
28
|
+
|
|
29
|
+
### 2. Prioritize
|
|
30
|
+
|
|
31
|
+
Rank content by importance:
|
|
32
|
+
|
|
33
|
+
| Priority | Content Type |
|
|
34
|
+
| :------- | :------------------------- |
|
|
35
|
+
| CRITICAL | Active code being modified |
|
|
36
|
+
| HIGH | Current task context |
|
|
37
|
+
| MEDIUM | Related code for reference |
|
|
38
|
+
| LOW | Completed discussions |
|
|
39
|
+
|
|
40
|
+
### 3. Compact
|
|
41
|
+
|
|
42
|
+
Summarize or remove low-priority content:
|
|
43
|
+
|
|
44
|
+
- Summarize completed tasks
|
|
45
|
+
- Remove verbose output
|
|
46
|
+
- Keep code snippets, remove explanations
|
|
47
|
+
|
|
48
|
+
### 4. Persist
|
|
49
|
+
|
|
50
|
+
Save important context externally:
|
|
51
|
+
|
|
52
|
+
- Update `session-state.json`
|
|
53
|
+
- Document decisions in `decisions/`
|
|
54
|
+
- Create checkpoints
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Integration
|
|
59
|
+
|
|
60
|
+
- Triggered at context warning threshold
|
|
61
|
+
- Can be invoked with `/compact`
|
|
62
|
+
- Preserves session continuity
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: testing-patterns
|
|
3
|
+
description: Testing strategies and patterns for quality assurance
|
|
4
|
+
triggers: [context, test, tdd, jest, vitest]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Testing Patterns Skill
|
|
8
|
+
|
|
9
|
+
> **Purpose**: Apply professional testing strategies for quality assurance
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
This skill provides comprehensive testing patterns for unit, integration, and end-to-end testing.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Testing Pyramid
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
/\
|
|
23
|
+
/E2E\ ← Few, slow, expensive
|
|
24
|
+
/──────\
|
|
25
|
+
/Integra-\ ← Some, medium speed
|
|
26
|
+
/ tion \
|
|
27
|
+
/────────────\
|
|
28
|
+
/ Unit \ ← Many, fast, cheap
|
|
29
|
+
/────────────────\
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Unit Testing
|
|
35
|
+
|
|
36
|
+
### AAA Pattern (Arrange-Act-Assert)
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
describe("UserService", () => {
|
|
40
|
+
it("should create a user with valid data", async () => {
|
|
41
|
+
// Arrange
|
|
42
|
+
const userData = { email: "test@example.com", name: "Test" };
|
|
43
|
+
const mockRepository = {
|
|
44
|
+
create: jest.fn().mockResolvedValue({ id: "1", ...userData }),
|
|
45
|
+
};
|
|
46
|
+
const service = new UserService(mockRepository);
|
|
47
|
+
|
|
48
|
+
// Act
|
|
49
|
+
const result = await service.createUser(userData);
|
|
50
|
+
|
|
51
|
+
// Assert
|
|
52
|
+
expect(result.id).toBe("1");
|
|
53
|
+
expect(result.email).toBe("test@example.com");
|
|
54
|
+
expect(mockRepository.create).toHaveBeenCalledWith(userData);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Test Naming
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
// Pattern: should_[expected]_when_[condition]
|
|
63
|
+
it('should throw ValidationError when email is invalid', () => { ... });
|
|
64
|
+
it('should return empty array when no users exist', () => { ... });
|
|
65
|
+
it('should hash password when creating user', () => { ... });
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Integration Testing
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
describe("POST /api/users", () => {
|
|
74
|
+
beforeAll(async () => {
|
|
75
|
+
await setupTestDatabase();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
afterAll(async () => {
|
|
79
|
+
await teardownTestDatabase();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should create user and return 201", async () => {
|
|
83
|
+
const response = await request(app)
|
|
84
|
+
.post("/api/users")
|
|
85
|
+
.send({ email: "test@example.com", password: "SecurePass123!" })
|
|
86
|
+
.expect(201);
|
|
87
|
+
|
|
88
|
+
expect(response.body.data.email).toBe("test@example.com");
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Mocking
|
|
96
|
+
|
|
97
|
+
### Mock Functions
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const mockSendEmail = jest.fn().mockResolvedValue({ sent: true });
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Mock Modules
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
jest.mock("./emailService", () => ({
|
|
107
|
+
sendEmail: jest.fn().mockResolvedValue({ sent: true }),
|
|
108
|
+
}));
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Spy Functions
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
const spy = jest.spyOn(userService, "validate");
|
|
115
|
+
await userService.createUser(data);
|
|
116
|
+
expect(spy).toHaveBeenCalled();
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Coverage Targets
|
|
122
|
+
|
|
123
|
+
| Metric | Target |
|
|
124
|
+
| :--------- | :----- |
|
|
125
|
+
| Lines | ≥80% |
|
|
126
|
+
| Branches | ≥75% |
|
|
127
|
+
| Functions | ≥80% |
|
|
128
|
+
| Statements | ≥80% |
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Quick Reference
|
|
133
|
+
|
|
134
|
+
| Pattern | Usage |
|
|
135
|
+
| :-------------- | :-------------------- |
|
|
136
|
+
| AAA | All unit tests |
|
|
137
|
+
| Given-When-Then | BDD style |
|
|
138
|
+
| Mocking | Isolate dependencies |
|
|
139
|
+
| Fixtures | Reusable test data |
|
|
140
|
+
| Factories | Generate test objects |
|
|
141
|
+
| Snapshot | UI components |
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: typescript-expert
|
|
3
|
+
description: Advanced TypeScript patterns and best practices
|
|
4
|
+
triggers: [context, typescript, types, generics]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# TypeScript Expert Skill
|
|
8
|
+
|
|
9
|
+
> **Purpose**: Apply advanced TypeScript patterns for type-safe code
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
This skill provides advanced TypeScript techniques for building robust, type-safe applications.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Utility Types
|
|
20
|
+
|
|
21
|
+
### Built-in Utilities
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// Partial - all properties optional
|
|
25
|
+
type UpdateUser = Partial<User>;
|
|
26
|
+
|
|
27
|
+
// Required - all properties required
|
|
28
|
+
type CompleteUser = Required<User>;
|
|
29
|
+
|
|
30
|
+
// Pick - select specific properties
|
|
31
|
+
type UserCredentials = Pick<User, "email" | "password">;
|
|
32
|
+
|
|
33
|
+
// Omit - exclude specific properties
|
|
34
|
+
type PublicUser = Omit<User, "password" | "hashedToken">;
|
|
35
|
+
|
|
36
|
+
// Record - key-value mapping
|
|
37
|
+
type UserRoles = Record<string, Role>;
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Generics
|
|
43
|
+
|
|
44
|
+
### Basic Generic
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
function identity<T>(value: T): T {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Constrained Generic
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
|
|
56
|
+
return obj[key];
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Generic Class
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
class Repository<T extends { id: string }> {
|
|
64
|
+
async findById(id: string): Promise<T | null> { ... }
|
|
65
|
+
async save(entity: T): Promise<T> { ... }
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Type Guards
|
|
72
|
+
|
|
73
|
+
### typeof Guard
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
function process(value: string | number) {
|
|
77
|
+
if (typeof value === "string") {
|
|
78
|
+
return value.toUpperCase();
|
|
79
|
+
}
|
|
80
|
+
return value * 2;
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### instanceof Guard
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
function handleError(error: Error | string) {
|
|
88
|
+
if (error instanceof ValidationError) {
|
|
89
|
+
return { code: "VALIDATION", message: error.message };
|
|
90
|
+
}
|
|
91
|
+
return { code: "UNKNOWN", message: String(error) };
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Custom Guard
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
interface User {
|
|
99
|
+
type: "user";
|
|
100
|
+
name: string;
|
|
101
|
+
}
|
|
102
|
+
interface Admin {
|
|
103
|
+
type: "admin";
|
|
104
|
+
name: string;
|
|
105
|
+
permissions: string[];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function isAdmin(person: User | Admin): person is Admin {
|
|
109
|
+
return person.type === "admin";
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Discriminated Unions
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
type Result<T> = { success: true; data: T } | { success: false; error: string };
|
|
119
|
+
|
|
120
|
+
function handleResult<T>(result: Result<T>) {
|
|
121
|
+
if (result.success) {
|
|
122
|
+
console.log(result.data); // TypeScript knows data exists
|
|
123
|
+
} else {
|
|
124
|
+
console.error(result.error); // TypeScript knows error exists
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Mapped Types
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
type Readonly<T> = {
|
|
135
|
+
readonly [P in keyof T]: T[P];
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
type Optional<T> = {
|
|
139
|
+
[P in keyof T]?: T[P];
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
type Nullable<T> = {
|
|
143
|
+
[P in keyof T]: T[P] | null;
|
|
144
|
+
};
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Quick Reference
|
|
150
|
+
|
|
151
|
+
| Pattern | Usage |
|
|
152
|
+
| :--------------- | :-------------------- |
|
|
153
|
+
| `Partial<T>` | Optional updates |
|
|
154
|
+
| `Required<T>` | Strict validation |
|
|
155
|
+
| `Pick<T, K>` | Select properties |
|
|
156
|
+
| `Omit<T, K>` | Exclude properties |
|
|
157
|
+
| `Record<K, V>` | Key-value maps |
|
|
158
|
+
| `Extract<T, U>` | Filter union types |
|
|
159
|
+
| `Exclude<T, U>` | Exclude union types |
|
|
160
|
+
| `NonNullable<T>` | Remove null/undefined |
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: verification-loop
|
|
3
|
+
description: Comprehensive verification running all quality gates
|
|
4
|
+
triggers: [manual, pre-commit]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Verification Loop Skill
|
|
8
|
+
|
|
9
|
+
> **Purpose**: Continuous quality assurance through automated verification
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
The verification loop runs all quality gates to ensure code meets professional standards before committing or deploying.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Workflow
|
|
20
|
+
|
|
21
|
+
### 1. Build Check
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm run build
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Pass Criteria**: Exit code 0, no TypeScript errors
|
|
28
|
+
|
|
29
|
+
### 2. Lint Check
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm run lint
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Pass Criteria**: No errors (warnings acceptable)
|
|
36
|
+
|
|
37
|
+
### 3. Type Check
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx tsc --noEmit
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Pass Criteria**: Zero type errors
|
|
44
|
+
|
|
45
|
+
### 4. Unit Tests
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm run test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Pass Criteria**: All tests pass
|
|
52
|
+
|
|
53
|
+
### 5. Coverage Check
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm run test:coverage
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Pass Criteria**: ≥80% coverage
|
|
60
|
+
|
|
61
|
+
### 6. Security Scan
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npm audit --audit-level=high
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Pass Criteria**: No high/critical vulnerabilities
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Configuration
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"verification": {
|
|
76
|
+
"coverageThreshold": 80,
|
|
77
|
+
"allowWarnings": true,
|
|
78
|
+
"securityLevel": "high"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Integration
|
|
86
|
+
|
|
87
|
+
- Invoked by `/verify` command
|
|
88
|
+
- Can be used as pre-commit hook
|
|
89
|
+
- Reports to Code Reviewer agent
|