sapper-iq 1.0.6 ā 1.0.8
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/PUBLISHING.md +6 -1
- package/package.json +1 -1
- package/sapper.mjs +291 -36
package/PUBLISHING.md
CHANGED
|
@@ -140,4 +140,9 @@ After publishing, users can install via:
|
|
|
140
140
|
- `npm install -g sapper` (from npm registry)
|
|
141
141
|
- `npm install -g git+https://github.com/aledanee/sapper.git` (from GitHub)
|
|
142
142
|
|
|
143
|
-
Keep both npm and GitHub versions synchronized.
|
|
143
|
+
Keep both npm and GitHub versions synchronized.
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
git add . && git commit -m "Add specialized Node.js/PostgreSQL prompts with use cases" && npm version patch && npm publish
|
package/package.json
CHANGED
package/sapper.mjs
CHANGED
|
@@ -93,6 +93,241 @@ function recreateReadline() {
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
// Specialized prompt profiles for different tasks
|
|
97
|
+
const PROMPT_PROFILES = {
|
|
98
|
+
documentation: `
|
|
99
|
+
šÆ DOCUMENTATION MODE ACTIVATED
|
|
100
|
+
Write comprehensive technical documentation. Execute tools to analyze codebase first.
|
|
101
|
+
|
|
102
|
+
Documentation Types & Formats:
|
|
103
|
+
|
|
104
|
+
**Use Cases:**
|
|
105
|
+
Title: [Action User Wants to Perform]
|
|
106
|
+
- Actor: [Who performs the action]
|
|
107
|
+
- Preconditions: [What must be true before]
|
|
108
|
+
- Main Flow:
|
|
109
|
+
1. User does X
|
|
110
|
+
2. System responds with Y
|
|
111
|
+
3. User confirms Z
|
|
112
|
+
- Postconditions: [Result after completion]
|
|
113
|
+
- Alternative Flows: [Error cases, edge cases]
|
|
114
|
+
|
|
115
|
+
**User Stories:**
|
|
116
|
+
"As a [role], I want [feature] so that [benefit]"
|
|
117
|
+
- Acceptance Criteria:
|
|
118
|
+
- Given [context]
|
|
119
|
+
- When [action]
|
|
120
|
+
- Then [result]
|
|
121
|
+
|
|
122
|
+
**BRD (Business Requirements Document):**
|
|
123
|
+
## Background
|
|
124
|
+
## Problem Statement
|
|
125
|
+
## Objectives
|
|
126
|
+
## Functional Requirements (numbered list)
|
|
127
|
+
## Non-Functional Requirements (performance, security, scalability)
|
|
128
|
+
## Success Metrics
|
|
129
|
+
## Timeline & Milestones
|
|
130
|
+
|
|
131
|
+
**Technical Documentation:**
|
|
132
|
+
- API endpoints with request/response examples
|
|
133
|
+
- Architecture diagrams (use mermaid)
|
|
134
|
+
- Setup instructions
|
|
135
|
+
- Environment variables
|
|
136
|
+
|
|
137
|
+
Execute [TOOL:LIST] and [TOOL:READ] to understand project before documenting.`,
|
|
138
|
+
|
|
139
|
+
backend: `
|
|
140
|
+
šÆ BACKEND MODE ACTIVATED - Node.js Specialist
|
|
141
|
+
Build server-side APIs, business logic, and integrations using Node.js/Express.
|
|
142
|
+
|
|
143
|
+
Tech Stack & Standards:
|
|
144
|
+
- Framework: Express.js or Fastify
|
|
145
|
+
- Runtime: Node.js (ES6+ with async/await)
|
|
146
|
+
- Architecture: MVC, Clean Architecture, or layered approach
|
|
147
|
+
|
|
148
|
+
Implementation Checklist:
|
|
149
|
+
ā RESTful API Design:
|
|
150
|
+
- GET /api/resource (list/read)
|
|
151
|
+
- POST /api/resource (create)
|
|
152
|
+
- PUT /PATCH /api/resource/:id (update)
|
|
153
|
+
- DELETE /api/resource/:id (delete)
|
|
154
|
+
- Return proper status codes: 200, 201, 400, 401, 404, 500
|
|
155
|
+
|
|
156
|
+
ā Request Handling:
|
|
157
|
+
- Use express.json() for body parsing
|
|
158
|
+
- Validate inputs with joi or zod
|
|
159
|
+
- Implement error middleware
|
|
160
|
+
- Add request logging (morgan/winston)
|
|
161
|
+
|
|
162
|
+
ā Security:
|
|
163
|
+
- Use helmet for security headers
|
|
164
|
+
- Implement CORS properly
|
|
165
|
+
- JWT authentication with bcrypt password hashing
|
|
166
|
+
- Rate limiting with express-rate-limit
|
|
167
|
+
- Input sanitization
|
|
168
|
+
|
|
169
|
+
ā Project Structure:
|
|
170
|
+
/src
|
|
171
|
+
/routes - API endpoints
|
|
172
|
+
/controllers - Request handlers
|
|
173
|
+
/services - Business logic
|
|
174
|
+
/models - Data models
|
|
175
|
+
/middleware - Auth, validation, errors
|
|
176
|
+
/config - Environment configs
|
|
177
|
+
/utils - Helper functions
|
|
178
|
+
|
|
179
|
+
ā Best Practices:
|
|
180
|
+
- Use environment variables (.env with dotenv)
|
|
181
|
+
- Implement graceful shutdown
|
|
182
|
+
- Add health check endpoint: GET /health
|
|
183
|
+
- Use async/await with try-catch
|
|
184
|
+
- Create separate router files
|
|
185
|
+
|
|
186
|
+
Execute tools to create Express server structure immediately.`,
|
|
187
|
+
|
|
188
|
+
frontend: `
|
|
189
|
+
šÆ FRONTEND MODE ACTIVATED
|
|
190
|
+
Focus on UI components, styling, and user interactions.
|
|
191
|
+
|
|
192
|
+
Implementation Rules:
|
|
193
|
+
- Component-based architecture (React/Vue/Svelte)
|
|
194
|
+
- Responsive design with mobile-first approach
|
|
195
|
+
- Use Tailwind CSS or styled-components
|
|
196
|
+
- Implement proper state management
|
|
197
|
+
- Add loading states and error boundaries
|
|
198
|
+
- Handle forms with validation
|
|
199
|
+
- Optimize for performance (lazy loading, memoization)
|
|
200
|
+
|
|
201
|
+
Execute tools to create component structure immediately.`,
|
|
202
|
+
|
|
203
|
+
testing: `
|
|
204
|
+
šÆ TESTING MODE ACTIVATED
|
|
205
|
+
Write comprehensive test suites with high coverage.
|
|
206
|
+
|
|
207
|
+
Test Requirements:
|
|
208
|
+
- Unit tests: Test individual functions/components
|
|
209
|
+
- Integration tests: Test feature workflows
|
|
210
|
+
- Use describe/it blocks with clear names
|
|
211
|
+
- Add assertions: expect().toBe(), toEqual(), toHaveBeenCalled()
|
|
212
|
+
- Mock external dependencies
|
|
213
|
+
- Test edge cases and error scenarios
|
|
214
|
+
- Aim for 80%+ coverage
|
|
215
|
+
|
|
216
|
+
Execute tools to create test files immediately.`,
|
|
217
|
+
|
|
218
|
+
database: `
|
|
219
|
+
šÆ DATABASE MODE ACTIVATED - PostgreSQL Specialist
|
|
220
|
+
Design schemas, write migrations, and optimize queries for PostgreSQL.
|
|
221
|
+
|
|
222
|
+
Tech Stack:
|
|
223
|
+
- Database: PostgreSQL 14+
|
|
224
|
+
- ORM Options: Prisma (recommended), Sequelize, or TypeORM
|
|
225
|
+
- Query Builder: Knex.js
|
|
226
|
+
- Migrations: Prisma Migrate or Knex migrations
|
|
227
|
+
|
|
228
|
+
Schema Design Best Practices:
|
|
229
|
+
ā Data Types:
|
|
230
|
+
- Use SERIAL or UUID for primary keys
|
|
231
|
+
- TEXT for variable strings (not VARCHAR)
|
|
232
|
+
- TIMESTAMP WITH TIME ZONE for dates
|
|
233
|
+
- JSONB for flexible data (indexed)
|
|
234
|
+
- ENUM types for fixed choices
|
|
235
|
+
|
|
236
|
+
ā Table Structure:
|
|
237
|
+
CREATE TABLE users (
|
|
238
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
239
|
+
email TEXT UNIQUE NOT NULL,
|
|
240
|
+
password_hash TEXT NOT NULL,
|
|
241
|
+
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
242
|
+
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
ā Relationships:
|
|
246
|
+
- Foreign Keys: REFERENCES other_table(id) ON DELETE CASCADE
|
|
247
|
+
- Indexes on FK columns: CREATE INDEX idx_user_id ON posts(user_id)
|
|
248
|
+
- Join tables for many-to-many
|
|
249
|
+
|
|
250
|
+
ā Performance:
|
|
251
|
+
- Add indexes on frequently queried columns
|
|
252
|
+
- Use partial indexes for conditional queries
|
|
253
|
+
- Create composite indexes for multi-column queries
|
|
254
|
+
- Analyze query plans: EXPLAIN ANALYZE
|
|
255
|
+
|
|
256
|
+
ā Migrations Pattern:
|
|
257
|
+
- Up: Create/alter tables and indexes
|
|
258
|
+
- Down: Rollback changes safely
|
|
259
|
+
- Version control all migrations
|
|
260
|
+
- Never edit existing migrations
|
|
261
|
+
|
|
262
|
+
ā Prisma Schema Example:
|
|
263
|
+
model User {
|
|
264
|
+
id String @id @default(uuid())
|
|
265
|
+
email String @unique
|
|
266
|
+
posts Post[]
|
|
267
|
+
createdAt DateTime @default(now())
|
|
268
|
+
updatedAt DateTime @updatedAt
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
ā Connection:
|
|
272
|
+
- Use connection pooling (pg.Pool)
|
|
273
|
+
- Set max connections: 20-50
|
|
274
|
+
- Use prepared statements
|
|
275
|
+
- Handle connection errors gracefully
|
|
276
|
+
|
|
277
|
+
ā Seed Data:
|
|
278
|
+
- Create seed files for development
|
|
279
|
+
- Use transactions for bulk inserts
|
|
280
|
+
- Make seeds idempotent
|
|
281
|
+
|
|
282
|
+
Execute tools to create schema files and migrations immediately.`,
|
|
283
|
+
|
|
284
|
+
devops: `
|
|
285
|
+
šÆ DEVOPS MODE ACTIVATED
|
|
286
|
+
Setup CI/CD, containerization, deployment automation.
|
|
287
|
+
|
|
288
|
+
DevOps Tasks:
|
|
289
|
+
- Write Dockerfile with multi-stage builds
|
|
290
|
+
- Create docker-compose.yml for local dev
|
|
291
|
+
- Setup GitHub Actions or GitLab CI
|
|
292
|
+
- Add environment-specific configs
|
|
293
|
+
- Implement health checks and monitoring
|
|
294
|
+
- Use secrets management
|
|
295
|
+
- Optimize build times
|
|
296
|
+
|
|
297
|
+
Execute tools to create config files immediately.`
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// Auto-detect task profile from user input
|
|
301
|
+
function detectTaskProfile(input) {
|
|
302
|
+
const text = input.toLowerCase();
|
|
303
|
+
|
|
304
|
+
// Documentation keywords
|
|
305
|
+
if (text.match(/\b(document|documentation|readme|brd|prd|user stor(y|ies)|use case|spec|wiki|guide)\b/))
|
|
306
|
+
return 'documentation';
|
|
307
|
+
|
|
308
|
+
// Backend keywords
|
|
309
|
+
if (text.match(/\b(api|endpoint|backend|server|route|controller|middleware|rest|graphql|service)\b/))
|
|
310
|
+
return 'backend';
|
|
311
|
+
|
|
312
|
+
// Frontend keywords
|
|
313
|
+
if (text.match(/\b(ui|frontend|component|page|design|style|css|tailwind|react|vue|svelte|button|form|navbar)\b/))
|
|
314
|
+
return 'frontend';
|
|
315
|
+
|
|
316
|
+
// Testing keywords
|
|
317
|
+
if (text.match(/\b(test|testing|spec|jest|vitest|cypress|unit test|integration|e2e|coverage)\b/))
|
|
318
|
+
return 'testing';
|
|
319
|
+
|
|
320
|
+
// Database keywords
|
|
321
|
+
if (text.match(/\b(database|schema|migration|model|orm|sql|postgres|mysql|mongo|prisma|sequelize)\b/))
|
|
322
|
+
return 'database';
|
|
323
|
+
|
|
324
|
+
// DevOps keywords
|
|
325
|
+
if (text.match(/\b(docker|container|ci\/cd|deploy|pipeline|kubernetes|k8s|helm|terraform|ansible)\b/))
|
|
326
|
+
return 'devops';
|
|
327
|
+
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
|
|
96
331
|
// --- Tool Logic ---
|
|
97
332
|
const tools = {
|
|
98
333
|
read: (path) => {
|
|
@@ -230,64 +465,75 @@ async function runSapper() {
|
|
|
230
465
|
if (messages.length === 0) {
|
|
231
466
|
messages = [{
|
|
232
467
|
role: 'system',
|
|
233
|
-
content: `You are Sapper, a senior software engineer AI assistant.
|
|
468
|
+
content: `You are Sapper, a senior software engineer AI assistant. Execute tools to COMPLETE tasks fully.
|
|
234
469
|
|
|
235
|
-
**
|
|
236
|
-
When
|
|
237
|
-
|
|
238
|
-
|
|
470
|
+
**COMPLETE TASK WORKFLOW:**
|
|
471
|
+
When user says "analyze files" ā DO ALL THESE STEPS IN ONE RESPONSE:
|
|
472
|
+
1. [TOOL:LIST]./[/TOOL] - see what files exist
|
|
473
|
+
2. [TOOL:READ]./file1.md[/TOOL] - read each relevant file
|
|
474
|
+
3. [TOOL:READ]./file2.md[/TOOL] - read more files as needed
|
|
475
|
+
4. Provide detailed analysis based on what you read
|
|
476
|
+
5. [SUMMARY:Analyzed X files, found Y patterns, created Z documentation]
|
|
239
477
|
|
|
240
|
-
|
|
478
|
+
ā WRONG (incomplete):
|
|
479
|
+
[TOOL:LIST]./[/TOOL]
|
|
480
|
+
(stops here - no reading, no analysis)
|
|
481
|
+
|
|
482
|
+
ā
CORRECT (complete):
|
|
483
|
+
[TOOL:LIST]./[/TOOL]
|
|
484
|
+
[TOOL:READ]./README.md[/TOOL]
|
|
485
|
+
[TOOL:READ]./docs.md[/TOOL]
|
|
486
|
+
|
|
487
|
+
Based on the files:
|
|
488
|
+
- README.md contains project setup instructions
|
|
489
|
+
- docs.md has API documentation for 5 endpoints
|
|
490
|
+
- The project uses Express.js with PostgreSQL
|
|
491
|
+
|
|
492
|
+
[SUMMARY:Analyzed 2 documentation files covering setup and API endpoints]
|
|
493
|
+
|
|
494
|
+
**TOOL FORMAT:**
|
|
241
495
|
[TOOL:TYPE]path]content[/TOOL]
|
|
242
496
|
|
|
243
497
|
**Available Tools:**
|
|
244
498
|
- SHELL: Execute commands
|
|
245
|
-
- READ: Read file contents
|
|
499
|
+
- READ: Read file contents (use this OFTEN!)
|
|
246
500
|
- WRITE: Create/update files
|
|
247
501
|
- MKDIR: Create directories
|
|
248
502
|
- LIST: List directory contents
|
|
249
503
|
- SEARCH: Search for patterns
|
|
250
504
|
|
|
251
|
-
**
|
|
505
|
+
**Format Examples:**
|
|
252
506
|
[TOOL:SHELL]npm install[/TOOL]
|
|
253
507
|
[TOOL:READ]./package.json[/TOOL]
|
|
254
508
|
[TOOL:WRITE]./app.js]console.log('hello')[/TOOL]
|
|
255
|
-
[TOOL:
|
|
256
|
-
[TOOL:
|
|
257
|
-
[TOOL:SEARCH]function myFunction[/TOOL]
|
|
509
|
+
[TOOL:LIST]./[/TOOL]
|
|
510
|
+
[TOOL:SEARCH]function auth[/TOOL]
|
|
258
511
|
|
|
259
|
-
**Multi-line
|
|
512
|
+
**Multi-line files:**
|
|
260
513
|
[TOOL:WRITE]./README.md]
|
|
261
514
|
# Title
|
|
262
515
|
- [ ] checkbox
|
|
263
|
-
- [x] done
|
|
264
516
|
Arrays: [1, 2, 3]
|
|
265
517
|
[/TOOL]
|
|
266
518
|
|
|
267
|
-
**
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
**Shell Commands:**
|
|
274
|
-
- Change directory with cd: [TOOL:SHELL]cd /path/to/project && npm install[/TOOL]
|
|
275
|
-
- Chain commands: cd /path && npm install && npm run dev
|
|
276
|
-
- Use non-interactive flags: npx create-next-app --typescript --no-git
|
|
519
|
+
**Multiple Tools Per Response:**
|
|
520
|
+
You MUST execute ALL necessary tools in ONE response. Example:
|
|
521
|
+
[TOOL:MKDIR]./src[/TOOL]
|
|
522
|
+
[TOOL:WRITE]./src/server.js]const express = require('express')[/TOOL]
|
|
523
|
+
[TOOL:WRITE]./package.json]{"name": "app"}[/TOOL]
|
|
277
524
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
2. For complex tasks: [PLAN:description] then execute each step
|
|
281
|
-
3. Multiple tools allowed per response
|
|
282
|
-
4. End with [SUMMARY:what was completed]
|
|
525
|
+
Created project structure with server and package.json.
|
|
526
|
+
[SUMMARY:Created Node.js project with Express server]
|
|
283
527
|
|
|
284
|
-
**
|
|
285
|
-
|
|
286
|
-
- Show examples of what "could" be done
|
|
287
|
-
- Use JSON format or markdown code blocks for tools
|
|
288
|
-
- Wait for permission - execute the tools
|
|
528
|
+
**Shell Commands:**
|
|
529
|
+
[TOOL:SHELL]cd /path && npm install && npm start[/TOOL]
|
|
289
530
|
|
|
290
|
-
**
|
|
531
|
+
**Critical Rules:**
|
|
532
|
+
1. Execute ALL needed tools in your response
|
|
533
|
+
2. Read files after listing them
|
|
534
|
+
3. Provide analysis/explanation after reading
|
|
535
|
+
4. End with [SUMMARY:what you completed]
|
|
536
|
+
5. NEVER just execute one tool and stop
|
|
291
537
|
|
|
292
538
|
Working directory: ${process.cwd()}`
|
|
293
539
|
}];
|
|
@@ -352,16 +598,25 @@ Working directory: ${process.cwd()}`
|
|
|
352
598
|
return ask();
|
|
353
599
|
}
|
|
354
600
|
|
|
601
|
+
// Auto-detect task profile and inject specialized instructions
|
|
602
|
+
const profile = detectTaskProfile(input);
|
|
603
|
+
let contextMsg = input;
|
|
604
|
+
|
|
605
|
+
// Inject profile if detected
|
|
606
|
+
if (profile) {
|
|
607
|
+
console.log(chalk.magenta(`\nšÆ ${profile.toUpperCase()} MODE DETECTED\n`));
|
|
608
|
+
contextMsg = `${input}\n\n${PROMPT_PROFILES[profile]}`;
|
|
609
|
+
}
|
|
610
|
+
|
|
355
611
|
// Check if user mentioned a directory and provide context
|
|
356
612
|
const dirMatch = input.match(/\/Users\/[^\s]+|\/[a-zA-Z0-9_\/-]+/g);
|
|
357
|
-
let contextMsg = input;
|
|
358
613
|
|
|
359
614
|
if (dirMatch && dirMatch[0]) {
|
|
360
615
|
const mentionedDir = dirMatch[0];
|
|
361
616
|
try {
|
|
362
617
|
if (fs.existsSync(mentionedDir) && fs.statSync(mentionedDir).isDirectory()) {
|
|
363
618
|
const files = fs.readdirSync(mentionedDir).slice(0, 10).join(', ');
|
|
364
|
-
contextMsg
|
|
619
|
+
contextMsg += `\n\n[CONTEXT: Directory "${mentionedDir}" contains: ${files}${fs.readdirSync(mentionedDir).length > 10 ? '...' : ''}]`;
|
|
365
620
|
}
|
|
366
621
|
} catch (e) {
|
|
367
622
|
// Silently ignore if directory doesn't exist
|