@devshub198211/devguard 2.0.1 → 2.0.3
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/MODULES.md +281 -0
- package/README.md +130 -139
- package/SETUP.md +111 -0
- package/dist/ai.d.ts +8 -0
- package/dist/ai.js +1 -1
- package/dist/{chunk-4WCL5IUZ.js → chunk-UXM7HRTI.js} +12 -2
- package/dist/cli.js +530 -173
- package/dist/index.js +1 -1
- package/package.json +16 -39
- package/dist/ai.cjs +0 -867
- package/dist/ai.d.cts +0 -169
- package/dist/api-contract-5kJEwFIh.d.cts +0 -157
- package/dist/auth.cjs +0 -787
- package/dist/auth.d.cts +0 -245
- package/dist/cli.cjs +0 -1162
- package/dist/cli.d.cts +0 -1
- package/dist/dx.cjs +0 -747
- package/dist/dx.d.cts +0 -96
- package/dist/index.cjs +0 -2655
- package/dist/index.d.cts +0 -38
- package/dist/security.cjs +0 -654
- package/dist/security.d.cts +0 -114
package/MODULES.md
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# DevGuard Modules Reference
|
|
2
|
+
|
|
3
|
+
All 14 modules explained with examples.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Security Modules
|
|
8
|
+
|
|
9
|
+
### 1. lockfile-guardian
|
|
10
|
+
**What:** Detects tampering in `package-lock.json`, `yarn.lock`, or `pnpm-lock.yaml` using SHA-512 hashing.
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { verifyLockfile, createSnapshot } from '@devshub198211/devguard/security';
|
|
14
|
+
|
|
15
|
+
// Create a trusted baseline after clean install
|
|
16
|
+
createSnapshot();
|
|
17
|
+
|
|
18
|
+
// Later, verify nothing has changed
|
|
19
|
+
const result = verifyLockfile();
|
|
20
|
+
if (!result.valid) console.log('Tampered files:', result.tampered);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
devguard snapshot # Create baseline
|
|
25
|
+
devguard check # Verify integrity
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
### 2. hook-scanner
|
|
31
|
+
**What:** Scans `node_modules` for 23+ malicious patterns in install scripts (obfuscation, network exfiltration, shell commands).
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { scanProject } from '@devshub198211/devguard/security';
|
|
35
|
+
|
|
36
|
+
const findings = scanProject();
|
|
37
|
+
findings.forEach(f => console.log(`${f.package}: ${f.pattern} [${f.severity}]`));
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
devguard scan
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
### 3. token-rotator
|
|
47
|
+
**What:** Checks API token age and verifies tokens are still valid via live API calls (opt-in).
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { checkTokenAge, loadTokensFromEnv } from '@devshub198211/devguard/security';
|
|
51
|
+
|
|
52
|
+
const tokens = loadTokensFromEnv(['NPM_TOKEN', 'GITHUB_TOKEN']);
|
|
53
|
+
const alerts = checkTokenAge(tokens);
|
|
54
|
+
alerts.filter(a => a.status === 'stale').forEach(a => console.log(`Rotate: ${a.name}`));
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
devguard tokens
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### 4. dep-pincer
|
|
64
|
+
**What:** Finds dependencies using ranges (`^1.0.0`) and pins them to exact versions. Generates SRI hashes.
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { autoPin } from '@devshub198211/devguard/security';
|
|
68
|
+
|
|
69
|
+
const result = autoPin('.', true); // true = auto-fix
|
|
70
|
+
console.log(`Pinned ${result.fixed} dependencies`);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
devguard pin --fix
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## AI & Code Modules
|
|
80
|
+
|
|
81
|
+
### 5. refactor-engine
|
|
82
|
+
**What:** Analyzes code for complexity (O(n) vs O(n²)), security flaws (eval, innerHTML), and structural issues. Opens a browser-based diff reviewer.
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
devguard refactor src/utils.ts
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Detects and fixes:
|
|
89
|
+
- `eval()` → `JSON.parse()` (security)
|
|
90
|
+
- `.innerHTML` → `.textContent` (XSS prevention)
|
|
91
|
+
- `var` → `const` (modern JS)
|
|
92
|
+
- Deep nesting → guard clauses (readability)
|
|
93
|
+
- Missing try/catch in async functions (error safety)
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
### 6. agent-schema
|
|
98
|
+
**What:** Type-safe schema builder for validating LLM JSON output with auto-retry and structural repair.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { c, parseWithRetry } from '@devshub198211/devguard/ai';
|
|
102
|
+
|
|
103
|
+
const TaskSchema = c.object({
|
|
104
|
+
title: c.string().min(1),
|
|
105
|
+
priority: c.string().enum(['high', 'medium', 'low']),
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const result = await parseWithRetry(TaskSchema, async (ctx) => {
|
|
109
|
+
return await callYourLLM(ctx);
|
|
110
|
+
});
|
|
111
|
+
// result.data is fully typed: { title: string; priority: 'high'|'medium'|'low' }
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
### 7. mcp-server-kit
|
|
117
|
+
**What:** Build Model Context Protocol servers that work with Claude Desktop and other MCP clients.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { MCPServerBuilder } from '@devshub198211/devguard/ai';
|
|
121
|
+
|
|
122
|
+
new MCPServerBuilder('my-tools', '1.0.0')
|
|
123
|
+
.addTool({
|
|
124
|
+
name: 'get_weather',
|
|
125
|
+
description: 'Get weather for a city',
|
|
126
|
+
inputSchema: { type: 'object', properties: { city: { type: 'string' } }, required: ['city'] },
|
|
127
|
+
handler: async ({ city }) => ({ temp: '22°C', city })
|
|
128
|
+
})
|
|
129
|
+
.startStdio();
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
devguard mcp
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
### 8. agent-memory
|
|
139
|
+
**What:** Persistent state storage for AI agents. Supports FileSystem and in-memory adapters.
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { FileSystemAdapter } from '@devshub198211/devguard/ai';
|
|
143
|
+
|
|
144
|
+
const memory = new FileSystemAdapter('.agent-data');
|
|
145
|
+
await memory.save('agent-1', {
|
|
146
|
+
id: '1', role: 'user', content: 'Hello', timestamp: Date.now()
|
|
147
|
+
});
|
|
148
|
+
const history = await memory.getHistory('agent-1', 10);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
### 9. llm-budget
|
|
154
|
+
**What:** Track token usage and spending across OpenAI, Anthropic, Google, and other LLM providers.
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { LLMBudget } from '@devshub198211/devguard/ai';
|
|
158
|
+
|
|
159
|
+
const budget = new LLMBudget({ monthlyLimitUSD: 50, warnAtUSD: 40 });
|
|
160
|
+
budget.track({
|
|
161
|
+
model: 'gpt-4o', provider: 'openai',
|
|
162
|
+
tokensPrompt: 1000, tokensCompletion: 500, costUSD: 0.015
|
|
163
|
+
});
|
|
164
|
+
console.log(budget.report()); // { totalCost, isOverBudget, ... }
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Auth Modules
|
|
170
|
+
|
|
171
|
+
### 10. zero-trust-jwt
|
|
172
|
+
**What:** JWT verification with HS256/RS256/JWKS support, revocation lists, and anomaly detection.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { JWTVerifier } from '@devshub198211/devguard/auth';
|
|
176
|
+
|
|
177
|
+
const verifier = new JWTVerifier({ secret: process.env.JWT_SECRET });
|
|
178
|
+
const { valid, payload, anomalies } = await verifier.verify(token);
|
|
179
|
+
// anomalies: { score: 0, level: 'safe', warnings: [] }
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
devguard jwt-verify --token <jwt> --secret <key>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
### 11. bot-fence
|
|
189
|
+
**What:** Multi-signal bot detection for Express/Fastify middleware. Checks IP, headers, rate limits.
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import { createMiddleware, IPRateLimiter } from '@devshub198211/devguard/auth';
|
|
193
|
+
|
|
194
|
+
app.use(createMiddleware({
|
|
195
|
+
blockThreshold: 70,
|
|
196
|
+
rateLimiter: new IPRateLimiter(100, 60_000)
|
|
197
|
+
}));
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
devguard bot-check
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
### 12. passkey-node
|
|
207
|
+
**What:** Complete WebAuthn/Passkey implementation using only Node.js crypto. Supports ES256 and RS256.
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
import {
|
|
211
|
+
generateRegistrationOptions,
|
|
212
|
+
verifyRegistration,
|
|
213
|
+
generateAuthenticationOptions,
|
|
214
|
+
verifyAuthentication
|
|
215
|
+
} from '@devshub198211/devguard/auth';
|
|
216
|
+
|
|
217
|
+
const options = generateRegistrationOptions({
|
|
218
|
+
rpId: 'example.com', rpName: 'My App',
|
|
219
|
+
userId: 'user-1', userName: 'alice'
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## DX Modules
|
|
226
|
+
|
|
227
|
+
### 13. env-safe
|
|
228
|
+
**What:** Validates `.env` files against a typed schema at startup. Fails fast with clear error messages.
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
import { loadEnv } from '@devshub198211/devguard/dx';
|
|
232
|
+
|
|
233
|
+
const env = loadEnv({
|
|
234
|
+
DATABASE_URL: { type: 'url', required: true },
|
|
235
|
+
PORT: { type: 'integer', default: '3000', min: 1, max: 65535 },
|
|
236
|
+
NODE_ENV: { type: 'string', enum: ['development', 'production', 'test'] },
|
|
237
|
+
});
|
|
238
|
+
// Throws immediately if any variable is missing or invalid
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
### 14. log-otlp
|
|
244
|
+
**What:** Structured JSON logger compatible with OpenTelemetry. Supports child loggers and trace injection.
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
import { createLogger } from '@devshub198211/devguard/dx';
|
|
248
|
+
|
|
249
|
+
const log = createLogger({ service: 'api', level: 'info' });
|
|
250
|
+
log.info('Request received', { userId: 'u-123', path: '/orders' });
|
|
251
|
+
log.error('Payment failed', { orderId: 'o-456', reason: 'declined' });
|
|
252
|
+
|
|
253
|
+
const reqLog = log.child({ requestId: 'req-789' });
|
|
254
|
+
reqLog.info('Processing');
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
### Bonus: api-contract
|
|
260
|
+
**What:** Zero-dependency schema builder with full TypeScript type inference for API validation.
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
import { c, validateBody } from '@devshub198211/devguard/dx';
|
|
264
|
+
|
|
265
|
+
const UserSchema = c.object({
|
|
266
|
+
name: c.string().min(1).max(100),
|
|
267
|
+
email: c.string(),
|
|
268
|
+
age: c.number().min(0).max(150).optional(),
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// Express middleware
|
|
272
|
+
app.post('/users', validateBody(UserSchema), (req, res) => {
|
|
273
|
+
// req.body is fully typed
|
|
274
|
+
});
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
*Your custom notes below:*
|
|
280
|
+
|
|
281
|
+
<!-- Add your personal notes, contact info, or acknowledgments here -->
|
package/README.md
CHANGED
|
@@ -1,167 +1,151 @@
|
|
|
1
|
-
# devguard
|
|
1
|
+
# @devshub198211/devguard
|
|
2
2
|
|
|
3
|
-
> **One install. 14
|
|
4
|
-
> Security · AI Tooling · Auth · DX — everything a production Node.js
|
|
3
|
+
> **One install. 14 modules. Zero external dependencies.**
|
|
4
|
+
> Security · AI Tooling · Auth · DX — everything a production Node.js project needs.
|
|
5
5
|
|
|
6
6
|
```bash
|
|
7
|
-
npm install devguard
|
|
8
|
-
npx devguard # instant security scan — no install needed
|
|
7
|
+
npm install @devshub198211/devguard
|
|
9
8
|
```
|
|
10
9
|
|
|
11
|
-
[](https://www.npmjs.com/package/devguard)
|
|
12
|
-
[](LICENSE)
|
|
13
|
-
[](package.json)
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## Features
|
|
18
|
-
|
|
19
|
-
| Category | Feature | What it does |
|
|
20
|
-
|----------|---------|-------------|
|
|
21
|
-
| 🔒 Security | `lockfile-guardian` | SHA-512 tamper detection for npm/yarn/pnpm lockfiles |
|
|
22
|
-
| 🔒 Security | `hook-scanner` | 23-rule malware scanner for install scripts (obfuscation-aware) |
|
|
23
|
-
| 🔒 Security | `token-rotator` | Live API verification + age alerts for npm/GitHub tokens |
|
|
24
|
-
| 🔒 Security | `dep-pincer` | Enforce exact version pins + SRI hash verification |
|
|
25
|
-
| 🤖 AI | `agent-schema` | Validate LLM JSON output, auto-retry on malformed responses |
|
|
26
|
-
| 🤖 AI | `mcp-server-kit` | Build Claude-compatible MCP tool servers in minutes |
|
|
27
|
-
| 🤖 AI | `agent-memory` | Durable agent state: Memory / FileSystem / Redis / DynamoDB |
|
|
28
|
-
| 🤖 AI | `llm-budget` | Token counting + cost tracking for OpenAI/Anthropic/Gemini |
|
|
29
|
-
| 🔑 Auth | `zero-trust-jwt` | JWT verify (HS256/RS256/JWKS), revocation, anomaly detection |
|
|
30
|
-
| 🔑 Auth | `bot-fence` | Multi-signal bot detection middleware for Express/Fastify |
|
|
31
|
-
| 🔑 Auth | `passkey-node` | Production WebAuthn passkey registration & authentication |
|
|
32
|
-
| 🛠 DX | `env-safe` | Typed .env validation with built-in parser — fail fast |
|
|
33
|
-
| 🛠 DX | `log-otlp` | Structured JSON logger with OpenTelemetry trace injection |
|
|
34
|
-
| 🛠 DX | `api-contract` | Zero-dep schema builder with full TypeScript type inference |
|
|
35
|
-
|
|
36
10
|
---
|
|
37
11
|
|
|
38
12
|
## Quick Start
|
|
39
13
|
|
|
40
|
-
### CLI
|
|
41
14
|
```bash
|
|
42
|
-
|
|
43
|
-
npx devguard
|
|
44
|
-
npx devguard lockfile verify # check integrity
|
|
45
|
-
npx devguard hooks # scan node_modules for malware
|
|
46
|
-
npx devguard pins --fix # auto-pin unpinned dependencies
|
|
47
|
-
npx devguard tokens --live # verify tokens via API
|
|
48
|
-
npx devguard --json # machine-readable output for CI
|
|
49
|
-
```
|
|
15
|
+
# Initialize DevGuard in your project
|
|
16
|
+
npx @devshub198211/devguard init
|
|
50
17
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
import { runAllChecks } from 'devguard';
|
|
18
|
+
# Run a full security audit
|
|
19
|
+
npx @devshub198211/devguard check
|
|
54
20
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!report.passedAll) process.exit(1);
|
|
21
|
+
# AI-powered code refactor (free, runs locally)
|
|
22
|
+
npx @devshub198211/devguard refactor src/app.ts
|
|
58
23
|
```
|
|
59
24
|
|
|
60
|
-
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
import { JWTVerifier } from 'devguard/auth';
|
|
65
|
-
import { loadEnv } from 'devguard/dx';
|
|
25
|
+
For global CLI access:
|
|
26
|
+
```bash
|
|
27
|
+
npm install -g @devshub198211/devguard
|
|
28
|
+
devguard check
|
|
66
29
|
```
|
|
67
30
|
|
|
68
31
|
---
|
|
69
32
|
|
|
70
|
-
##
|
|
33
|
+
## All 14 Modules
|
|
34
|
+
|
|
35
|
+
| # | Category | Module | CLI Command | What It Does |
|
|
36
|
+
|---|----------|--------|-------------|--------------|
|
|
37
|
+
| 1 | 🔒 Security | `lockfile-guardian` | `check` / `snapshot` | SHA-512 lockfile tamper detection |
|
|
38
|
+
| 2 | 🔒 Security | `hook-scanner` | `scan` | 23-rule malware scanner for install scripts |
|
|
39
|
+
| 3 | 🔒 Security | `token-rotator` | `tokens` | Live API token verification + age alerts |
|
|
40
|
+
| 4 | 🔒 Security | `dep-pincer` | `pin --fix` | Enforce exact version pins + SRI hashes |
|
|
41
|
+
| 5 | 🤖 AI | `refactor-engine` | `refactor <file>` | Complexity analysis + security patching |
|
|
42
|
+
| 6 | 🤖 AI | `agent-schema` | `schema <json>` | Validate & auto-repair LLM JSON output |
|
|
43
|
+
| 7 | 🤖 AI | `mcp-server-kit` | `mcp` | Build Claude-compatible MCP tool servers |
|
|
44
|
+
| 8 | 🤖 AI | `agent-memory` | `memory --agent <id>` | Durable state for AI agents (FS/Redis) |
|
|
45
|
+
| 9 | 🤖 AI | `llm-budget` | `budget` | Token counting + cost tracking |
|
|
46
|
+
| 10 | 🔑 Auth | `zero-trust-jwt` | `jwt-verify` / `jwt-sign` | JWT sign & verify with anomaly detection |
|
|
47
|
+
| 11 | 🔑 Auth | `bot-fence` | `bot-check --ip <ip>` | Multi-signal bot detection middleware |
|
|
48
|
+
| 12 | 🔑 Auth | `passkey-node` | `passkey-verify` | WebAuthn passkey registration & auth |
|
|
49
|
+
| 13 | 🛠 DX | `env-safe` | `env-verify` | Typed .env validation — fail fast |
|
|
50
|
+
| 14 | 🛠 DX | `log-otlp` | `log --msg <text>` | Structured JSON logger + OpenTelemetry |
|
|
51
|
+
|
|
52
|
+
**Bonus:** `api-contract` — zero-dep schema builder with TypeScript inference.
|
|
71
53
|
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
import { runAllChecks } from 'devguard';
|
|
75
|
-
const report = await runAllChecks();
|
|
76
|
-
console.log(`Security score: ${report.score}/100`);
|
|
77
|
-
```
|
|
54
|
+
---
|
|
78
55
|
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
import { c, parseWithRetry } from 'devguard';
|
|
82
|
-
|
|
83
|
-
const TaskSchema = c.object({
|
|
84
|
-
title: c.string().min(1),
|
|
85
|
-
priority: c.string().enum(["high","medium","low"]),
|
|
86
|
-
dueDate: c.string().optional(),
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const result = await parseWithRetry(TaskSchema, async (ctx) => {
|
|
90
|
-
return await callYourLLM(ctx); // your LLM call here
|
|
91
|
-
});
|
|
92
|
-
// result.data is fully typed: { title: string; priority: "high"|"medium"|"low"; dueDate?: string }
|
|
93
|
-
```
|
|
56
|
+
## Use From Any Language (Python, Go, Bash, etc.)
|
|
94
57
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
58
|
+
Every command supports `--json` output, making DevGuard usable from **any programming language**:
|
|
59
|
+
|
|
60
|
+
### Python
|
|
61
|
+
```python
|
|
62
|
+
import subprocess, json
|
|
98
63
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
64
|
+
result = subprocess.run(
|
|
65
|
+
["npx", "@devshub198211/devguard", "check", "--json"],
|
|
66
|
+
capture_output=True, text=True
|
|
67
|
+
)
|
|
68
|
+
report = json.loads(result.stdout)
|
|
69
|
+
print(f"Security Score: {report['score']}/100")
|
|
104
70
|
```
|
|
105
71
|
|
|
106
|
-
###
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
.addTool({
|
|
112
|
-
name: 'get_weather',
|
|
113
|
-
description: 'Get weather for a city',
|
|
114
|
-
inputSchema: { type:'object', properties:{ city:{type:'string'} }, required:['city'] },
|
|
115
|
-
handler: async ({ city }) => ({ temp: '22°C', city })
|
|
116
|
-
})
|
|
117
|
-
.startStdio(); // works with Claude Desktop + any MCP client
|
|
72
|
+
### Go
|
|
73
|
+
```go
|
|
74
|
+
cmd := exec.Command("npx", "@devshub198211/devguard", "scan", "--json")
|
|
75
|
+
output, _ := cmd.Output()
|
|
76
|
+
// Parse JSON output
|
|
118
77
|
```
|
|
119
78
|
|
|
120
|
-
###
|
|
121
|
-
```
|
|
122
|
-
|
|
79
|
+
### Bash
|
|
80
|
+
```bash
|
|
81
|
+
SCORE=$(npx @devshub198211/devguard check --json | jq '.score')
|
|
82
|
+
echo "Score: $SCORE"
|
|
123
83
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
84
|
+
# Sign a JWT
|
|
85
|
+
TOKEN=$(devguard jwt-sign --payload '{"sub":"user-1"}' --secret mykey --json | jq -r '.token')
|
|
86
|
+
|
|
87
|
+
# Check an IP
|
|
88
|
+
devguard bot-check --ip 203.0.113.5 --json | jq '.verdict'
|
|
127
89
|
```
|
|
128
90
|
|
|
129
|
-
###
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const app = express();
|
|
135
|
-
app.use(createMiddleware({
|
|
136
|
-
blockThreshold: 70,
|
|
137
|
-
rateLimiter: new IPRateLimiter(100, 60_000)
|
|
138
|
-
}));
|
|
91
|
+
### Ruby
|
|
92
|
+
```ruby
|
|
93
|
+
result = `npx @devshub198211/devguard check --json`
|
|
94
|
+
report = JSON.parse(result)
|
|
95
|
+
puts "Score: #{report['score']}"
|
|
139
96
|
```
|
|
140
97
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## CLI Reference
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# Core
|
|
104
|
+
devguard init # Set up project
|
|
105
|
+
devguard check [--json] # Full security audit
|
|
106
|
+
devguard refactor <file> [--json] # AI code refactor
|
|
107
|
+
devguard mcp # Start MCP server
|
|
108
|
+
|
|
109
|
+
# Security
|
|
110
|
+
devguard snapshot # Create lockfile baseline
|
|
111
|
+
devguard scan [--json] # Malware scan
|
|
112
|
+
devguard tokens [--json] # Token health check
|
|
113
|
+
devguard pin [--fix] [--json] # Pin dependencies
|
|
114
|
+
|
|
115
|
+
# AI
|
|
116
|
+
devguard schema '<json>' [--json] # Validate JSON
|
|
117
|
+
devguard memory [--agent <id>] [--json] # Query agent state
|
|
118
|
+
devguard budget [--json] # LLM cost summary
|
|
119
|
+
|
|
120
|
+
# Auth
|
|
121
|
+
devguard jwt-verify --token <t> --secret <s> # Verify JWT
|
|
122
|
+
devguard jwt-sign --payload '<json>' --secret <s> # Sign JWT
|
|
123
|
+
devguard bot-check --ip <ip> [--json] # Bot detection
|
|
124
|
+
|
|
125
|
+
# DX
|
|
126
|
+
devguard env-verify [--file .env] [--json] # Validate env
|
|
127
|
+
devguard log --msg <text> [--level info|warn|error] # Emit log
|
|
152
128
|
```
|
|
153
129
|
|
|
154
|
-
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Programmatic Usage (Node.js / TypeScript)
|
|
133
|
+
|
|
155
134
|
```typescript
|
|
156
|
-
import {
|
|
135
|
+
import { runAllChecks } from '@devshub198211/devguard';
|
|
157
136
|
|
|
158
|
-
const
|
|
159
|
-
log
|
|
160
|
-
|
|
137
|
+
const report = await runAllChecks();
|
|
138
|
+
console.log(`Security Score: ${report.score}/100`);
|
|
139
|
+
if (!report.passedAll) process.exit(1);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Tree-Shakeable Sub-Path Imports
|
|
161
143
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
144
|
+
```typescript
|
|
145
|
+
import { verifyLockfile } from '@devshub198211/devguard/security';
|
|
146
|
+
import { LLMBudget } from '@devshub198211/devguard/ai';
|
|
147
|
+
import { JWTVerifier } from '@devshub198211/devguard/auth';
|
|
148
|
+
import { loadEnv } from '@devshub198211/devguard/dx';
|
|
165
149
|
```
|
|
166
150
|
|
|
167
151
|
---
|
|
@@ -179,29 +163,36 @@ jobs:
|
|
|
179
163
|
- uses: actions/setup-node@v4
|
|
180
164
|
with: { node-version: '20' }
|
|
181
165
|
- run: npm ci
|
|
182
|
-
- run: npx devguard --json >
|
|
183
|
-
|
|
184
|
-
DEVGUARD_TOKENS: NPM_TOKEN,GITHUB_TOKEN
|
|
185
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
186
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
187
|
-
- uses: actions/upload-artifact@v4
|
|
188
|
-
with: { name: security-report, path: devguard-report.json }
|
|
189
|
-
- run: node -e "const r=require('./devguard-report.json'); if(!r.passedAll) process.exit(1)"
|
|
166
|
+
- run: npx @devshub198211/devguard check --json > report.json
|
|
167
|
+
- run: node -e "const r=JSON.parse(require('fs').readFileSync('report.json'));if(!r.passedAll)process.exit(1)"
|
|
190
168
|
```
|
|
191
169
|
|
|
192
170
|
---
|
|
193
171
|
|
|
194
|
-
## Security
|
|
172
|
+
## Security Guarantees
|
|
195
173
|
|
|
196
174
|
- ✅ **Zero external runtime dependencies** — only Node.js built-ins
|
|
197
|
-
- ✅ **No network calls** at runtime except
|
|
175
|
+
- ✅ **No network calls** at runtime (except opt-in token verification)
|
|
198
176
|
- ✅ **No telemetry, no tracking, no phone-home**
|
|
199
|
-
- ✅ **Constant-time JWT comparison** —
|
|
177
|
+
- ✅ **Constant-time JWT comparison** — timing attack protection
|
|
200
178
|
- ✅ **Sign-count replay protection** in WebAuthn
|
|
179
|
+
- ✅ **Path traversal protection** — all file IDs are SHA-256 hashed
|
|
180
|
+
- ✅ **Prototype pollution prevention** in CBOR/JSON parsers
|
|
181
|
+
- ✅ **Atomic file writes** — no data corruption during crashes
|
|
201
182
|
- ✅ **Works fully offline** — all security checks are local
|
|
202
183
|
|
|
203
184
|
---
|
|
204
185
|
|
|
186
|
+
## Requirements
|
|
187
|
+
|
|
188
|
+
- Node.js >= 18.0.0
|
|
189
|
+
|
|
205
190
|
## License
|
|
206
191
|
|
|
207
192
|
MIT © DevGuard Contributors
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
*Your custom notes below:*
|
|
197
|
+
|
|
198
|
+
<!-- Add your personal notes, contact info, or acknowledgments here -->
|