codeninja 3.2.0 → 4.0.1
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 +15 -4
- package/agent/database-agent.md +24 -1
- package/agent/nodejs-agent.md +79 -0
- package/cli.js +27 -7
- package/commands/audit.workflow.md +4 -1
- package/commands/db-create-table.workflow.md +1 -1
- package/commands/initialize-project.workflow.md +21 -0
- package/ide/antigravity/.agents/personas/database-architect.md +431 -153
- package/ide/antigravity/.agents/personas/global-orchestrator.md +202 -85
- package/ide/antigravity/.agents/personas/nodejs-backend.md +368 -133
- package/ide/antigravity/.agents/personas/reactjs-frontend.md +182 -101
- package/ide/antigravity/.agents/skills/api-builder/SKILL.md +58 -0
- package/ide/antigravity/.agents/skills/code-intelligence/SKILL.md +22 -0
- package/ide/antigravity/.agents/skills/database/SKILL.md +32 -0
- package/ide/antigravity/.agents/skills/mcp-and-context/SKILL.md +76 -82
- package/ide/antigravity/.agents/skills/reactjs/SKILL.md +36 -0
- package/ide/antigravity/.agents/workflows/codeninja-api.md +76 -83
- package/ide/antigravity/.agents/workflows/codeninja-audit.md +82 -44
- package/ide/antigravity/.agents/workflows/codeninja-db-create.md +107 -94
- package/ide/antigravity/.agents/workflows/codeninja-db-drop.md +89 -67
- package/ide/antigravity/.agents/workflows/codeninja-db-index.md +86 -54
- package/ide/antigravity/.agents/workflows/codeninja-db-modify.md +126 -68
- package/ide/antigravity/.agents/workflows/codeninja-db-seed.md +87 -59
- package/ide/antigravity/.agents/workflows/codeninja-db-sync.md +77 -41
- package/ide/antigravity/.agents/workflows/codeninja-debug.md +35 -21
- package/ide/antigravity/.agents/workflows/codeninja-design.md +49 -35
- package/ide/antigravity/.agents/workflows/codeninja-explain.md +41 -20
- package/ide/antigravity/.agents/workflows/codeninja-init.md +479 -289
- package/ide/antigravity/.agents/workflows/codeninja-integrate-api.md +253 -136
- package/ide/antigravity/.agents/workflows/codeninja-modularize.md +250 -132
- package/ide/antigravity/.agents/workflows/codeninja-optimize.md +71 -29
- package/ide/antigravity/.agents/workflows/codeninja-refactor.md +50 -42
- package/ide/antigravity/.agents/workflows/codeninja-review.md +38 -21
- package/ide/antigravity/.agents/workflows/codeninja-sync.md +922 -141
- package/ide/antigravity/.agents/workflows/codeninja-test.md +34 -49
- package/ide/antigravity/.agents/workflows/codeninja-validate-page.md +449 -151
- package/ide/claude-code/.claude/CLAUDE.md +99 -0
- package/ide/claude-code/.claude/agents/database-agent.md +535 -0
- package/ide/claude-code/.claude/agents/nodejs-agent.md +493 -0
- package/ide/claude-code/.claude/agents/reactjs-agent.md +267 -0
- package/ide/claude-code/.claude/commands/codeninja-api.md +104 -0
- package/ide/claude-code/.claude/commands/codeninja-audit.md +119 -0
- package/ide/claude-code/.claude/commands/codeninja-db-create.md +138 -0
- package/ide/claude-code/.claude/commands/codeninja-db-drop.md +109 -0
- package/ide/claude-code/.claude/commands/codeninja-db-index.md +103 -0
- package/ide/claude-code/.claude/commands/codeninja-db-modify.md +165 -0
- package/ide/claude-code/.claude/commands/codeninja-db-seed.md +104 -0
- package/ide/claude-code/.claude/commands/codeninja-db-sync.md +106 -0
- package/ide/claude-code/.claude/commands/codeninja-debug.md +99 -0
- package/ide/claude-code/.claude/commands/codeninja-design.md +68 -0
- package/ide/claude-code/.claude/commands/codeninja-explain.md +61 -0
- package/ide/claude-code/.claude/commands/codeninja-init.md +529 -0
- package/ide/claude-code/.claude/commands/codeninja-integrate-api.md +453 -0
- package/ide/claude-code/.claude/commands/codeninja-modularize.md +334 -0
- package/ide/claude-code/.claude/commands/codeninja-optimize.md +129 -0
- package/ide/claude-code/.claude/commands/codeninja-refactor.md +76 -0
- package/ide/claude-code/.claude/commands/codeninja-review.md +87 -0
- package/ide/claude-code/.claude/commands/codeninja-sync.md +964 -0
- package/ide/claude-code/.claude/commands/codeninja-test.md +45 -0
- package/ide/claude-code/.claude/commands/codeninja-validate-page.md +548 -0
- package/ide/cursor/.cursor/rules/01-global-orchestrator.mdc +12 -13
- package/ide/cursor/.cursor/rules/02-mcp-and-context.mdc +47 -31
- package/ide/cursor/.cursor/rules/03-api-builder.mdc +32 -110
- package/ide/cursor/.cursor/rules/04-nodejs-generation.mdc +58 -0
- package/ide/cursor/.cursor/rules/05-database.mdc +54 -0
- package/ide/cursor/.cursor/rules/06-reactjs.mdc +36 -0
- package/ide/cursor/.cursor/rules/07-reactjs-generation.mdc +49 -0
- package/ide/cursor/.cursor/rules/08-code-intelligence.mdc +56 -0
- package/ide/cursor/.cursor/rules/09-workflow-steps.mdc +53 -0
- package/ide/vscode/.github/copilot-instructions.md +67 -382
- package/ide/vscode/.vscode/instructions/code-intelligence.instructions.md +58 -0
- package/ide/vscode/.vscode/instructions/database.instructions.md +55 -0
- package/ide/vscode/.vscode/instructions/nodejs.instructions.md +77 -0
- package/ide/vscode/.vscode/instructions/reactjs.instructions.md +42 -0
- package/package.json +2 -2
- package/tasks/ask-hashing-library.task.md +31 -0
- package/tasks/ask-language-type.task.md +26 -0
- package/tasks/ask-new-module-name.task.md +13 -0
- package/tasks/ask-new-service-name.task.md +13 -0
- package/tasks/ask-old-module-name.task.md +15 -0
- package/tasks/ask-old-service-name.task.md +13 -0
- package/tasks/ask-orm-type.task.md +26 -0
- package/tasks/collect-seed-data.task.md +19 -0
- package/tasks/generate-app.task.md +42 -0
- package/tasks/generate-common.task.md +13 -0
- package/tasks/generate-constants.task.md +13 -0
- package/tasks/generate-database.task.md +32 -0
- package/tasks/generate-encryption.task.md +28 -0
- package/tasks/generate-fast-defaults.task.md +7 -0
- package/tasks/generate-hashing.task.md +180 -0
- package/tasks/generate-headerValidator.task.md +13 -0
- package/tasks/generate-ioRedis.task.md +20 -0
- package/tasks/generate-language-en.task.md +12 -0
- package/tasks/generate-logging.task.md +12 -0
- package/tasks/generate-model.task.md +74 -6
- package/tasks/generate-notification.task.md +12 -0
- package/tasks/generate-package-json.task.md +69 -0
- package/tasks/generate-prisma-client.task.md +56 -0
- package/tasks/generate-prisma-schema.task.md +71 -0
- package/tasks/generate-rateLimiter.task.md +20 -0
- package/tasks/generate-readme.task.md +24 -0
- package/tasks/generate-response.task.md +27 -0
- package/tasks/generate-route-manager.task.md +32 -0
- package/tasks/generate-route.task.md +37 -0
- package/tasks/generate-swagger.task.md +8 -0
- package/tasks/generate-template.task.md +12 -0
- package/tasks/generate-tsconfig.task.md +38 -0
- package/tasks/generate-validator.task.md +31 -0
- package/ide/cursor/.cursor/rules/04-database.mdc +0 -90
- package/ide/cursor/.cursor/rules/05-reactjs.mdc +0 -147
- package/ide/cursor/.cursor/rules/06-code-intelligence.mdc +0 -112
|
@@ -1,111 +1,105 @@
|
|
|
1
1
|
---
|
|
2
2
|
skill: mcp-and-context
|
|
3
|
-
scope:
|
|
3
|
+
scope: all-commands
|
|
4
|
+
loaded-for:
|
|
5
|
+
- all commands (always active)
|
|
4
6
|
description: >
|
|
5
|
-
MCP
|
|
6
|
-
|
|
7
|
+
All MCP tools available in this project, the complete context.json schema
|
|
8
|
+
(including v4.0 fields), and the stale scratchpad recovery procedure.
|
|
7
9
|
---
|
|
8
10
|
|
|
9
|
-
# Skill: MCP and Context
|
|
11
|
+
# Skill: MCP and Context
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
context.json. Every persona must follow these rules without exception.
|
|
13
|
-
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
## Available MCP Tools
|
|
13
|
+
## All MCP Tools
|
|
17
14
|
|
|
18
15
|
| Tool | Purpose | When to use |
|
|
19
|
-
|
|
20
|
-
| `context_read` | Load full
|
|
21
|
-
| `context_write` |
|
|
22
|
-
| `context_clear_scratchpad` | Clear
|
|
23
|
-
| `context_check_stale` | Detect unresolved scratchpad | Step 0 of activation |
|
|
24
|
-
| `service_scan` | Discover all
|
|
25
|
-
| `migration_next_number` | Get next sequential migration number | Before
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| `context_read` | Load full context.json into memory | FIRST on every activation |
|
|
18
|
+
| `context_write` | Deep-merge updates into context.json | After every completed operation |
|
|
19
|
+
| `context_clear_scratchpad` | Clear current_* scratchpad key | After writing context post-workflow |
|
|
20
|
+
| `context_check_stale` | Detect unresolved scratchpad operations | Step 0 of every activation |
|
|
21
|
+
| `service_scan` | Discover all service directories on disk | Step 2 of activation; compare with context.services |
|
|
22
|
+
| `migration_next_number` | Get next sequential migration number | Before generating any migration file |
|
|
26
23
|
| `fs_read` | Read a file from disk | Before modifying any existing file |
|
|
27
|
-
| `fs_list` | List directory contents | When scanning structure |
|
|
28
|
-
| `fs_exists` | Check if file/directory exists | Before conditional operations |
|
|
29
|
-
| `file_insert_after` |
|
|
30
|
-
| `file_contains` | Check if
|
|
31
|
-
| `run_drift_check` | Compare context vs disk | During
|
|
32
|
-
| `lint_file` | Lint a generated file | After
|
|
33
|
-
| `
|
|
34
|
-
| `
|
|
35
|
-
| `
|
|
36
|
-
| `
|
|
37
|
-
| `
|
|
38
|
-
| `
|
|
39
|
-
| `
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
## Absolute Rules
|
|
46
|
-
|
|
47
|
-
- NEVER read `context.json` directly with `fs_read` — always use `context_read`
|
|
48
|
-
- NEVER write `context.json` directly — always use `context_write`
|
|
49
|
-
- `context_write` deep-merges — it never overwrites the whole file
|
|
50
|
-
- `change_log` is append-only — never delete entries
|
|
51
|
-
- NEVER assume a stored value — always read from loaded context object
|
|
52
|
-
- `context_version` is managed automatically — if `context_read` returns a
|
|
53
|
-
higher version than expected, the file was modified externally — re-read before acting
|
|
54
|
-
|
|
55
|
-
---
|
|
56
|
-
|
|
57
|
-
## Context Schema Reference
|
|
24
|
+
| `fs_list` | List directory contents | When scanning project structure |
|
|
25
|
+
| `fs_exists` | Check if a file/directory exists | Before conditional operations |
|
|
26
|
+
| `file_insert_after` | Surgically insert content after a marker | route_manager.js, swagger_doc.json — never rewrite |
|
|
27
|
+
| `file_contains` | Check if file already contains a string | Before appending to avoid duplicates |
|
|
28
|
+
| `run_drift_check` | Compare context vs actual files on disk | During /codeninja:sync |
|
|
29
|
+
| `lint_file` | Lint a generated JS/TS file | After any JS/TS file generation |
|
|
30
|
+
| `analyze_middleware_order` | Verify middleware chain order | During /codeninja:audit |
|
|
31
|
+
| `analyze_encryption_library` | Verify encryption library usage | During /codeninja:audit |
|
|
32
|
+
| `analyze_language_keys` | Check i18n key consistency | During /codeninja:audit |
|
|
33
|
+
| `analyze_dependencies` | Scan package.json for issues | During /codeninja:audit |
|
|
34
|
+
| `analyze_env_file` | Check .env completeness | During /codeninja:audit |
|
|
35
|
+
| `validate_redis_connection` | Test Redis connectivity | During /codeninja:init |
|
|
36
|
+
| `validate_postgres_connection` | Test PostgreSQL connectivity | During /codeninja:init |
|
|
37
|
+
|
|
38
|
+
## Context.json Schema (v4.0)
|
|
58
39
|
|
|
59
40
|
```json
|
|
60
41
|
{
|
|
61
42
|
"context_version": 0,
|
|
62
43
|
"project_name": "",
|
|
44
|
+
"initialized_at": "",
|
|
45
|
+
"last_updated_at": "",
|
|
46
|
+
"last_command": "",
|
|
47
|
+
"repository_state": "fresh|existing",
|
|
63
48
|
"project_info": {
|
|
64
49
|
"summary": "",
|
|
65
50
|
"detected_entities": [],
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"from_figma": { "screens": [] }
|
|
51
|
+
"has_doc": false,
|
|
52
|
+
"has_sow": false,
|
|
53
|
+
"has_figma": false
|
|
70
54
|
},
|
|
71
55
|
"db": {
|
|
72
|
-
"type": "",
|
|
73
|
-
"
|
|
74
|
-
"host": "",
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
56
|
+
"type": "postgres|mysql|mongodb",
|
|
57
|
+
"orm": "none|prisma",
|
|
58
|
+
"name": "", "host": "", "port": 0, "user": "",
|
|
59
|
+
"schema": { "tables": {}, "change_log": [] }
|
|
60
|
+
},
|
|
61
|
+
"services": {
|
|
62
|
+
"<service_name>": {
|
|
63
|
+
"type": "nodejs|reactjs",
|
|
64
|
+
"language": "javascript|typescript",
|
|
65
|
+
"hashing_library": "bcryptjs|argon2",
|
|
66
|
+
"port": 0,
|
|
67
|
+
"client_type": "reactjs|app",
|
|
68
|
+
"encrypted_transport": true,
|
|
69
|
+
"supported_languages": ["en"],
|
|
70
|
+
"encryption_key": "",
|
|
71
|
+
"encryption_iv": "",
|
|
72
|
+
"api_key": "",
|
|
73
|
+
"modules": [],
|
|
74
|
+
"linked_service": "",
|
|
75
|
+
"linked_service_port": 0
|
|
76
|
+
}
|
|
78
77
|
},
|
|
79
|
-
"services": {},
|
|
80
78
|
"api_routes": [],
|
|
81
|
-
"change_log": []
|
|
79
|
+
"change_log": [],
|
|
80
|
+
"current_init": {},
|
|
81
|
+
"current_api": {},
|
|
82
|
+
"current_action": {}
|
|
82
83
|
}
|
|
83
84
|
```
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
Temporary keys written during multi-step workflows:
|
|
86
|
+
**New v4.0 fields:**
|
|
87
|
+
- `db.orm` — "none" (raw driver) or "prisma" (Prisma ORM)
|
|
88
|
+
- `services[name].language` — "javascript" or "typescript"
|
|
89
|
+
- `services[name].hashing_library` — "bcryptjs" or "argon2"
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|-----|---------|
|
|
93
|
-
| `current_init` | initialize-project workflow |
|
|
94
|
-
| `current_api` | create-api workflow |
|
|
95
|
-
| `current_table` | db-create-table workflow |
|
|
96
|
-
| `current_modify` | db-modify-table workflow |
|
|
97
|
-
| `current_index` | db-add-index workflow |
|
|
98
|
-
| `current_design` | design workflow |
|
|
91
|
+
## Context Rules
|
|
99
92
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
93
|
+
- `context_write` deep-merges — it never replaces the whole file
|
|
94
|
+
- `change_log` is append-only — never delete or modify entries
|
|
95
|
+
- `context_version` auto-increments on each write
|
|
96
|
+
- Stale scratchpad: if `context_check_stale` returns unresolved keys, resolve them before any other operation
|
|
97
|
+
- After every completed workflow: call `context_write` then `context_clear_scratchpad`
|
|
104
98
|
|
|
105
99
|
## Stale Scratchpad Recovery
|
|
106
100
|
|
|
107
|
-
|
|
108
|
-
1.
|
|
109
|
-
2. Ask: "
|
|
110
|
-
3. If resume
|
|
111
|
-
4. If discard
|
|
101
|
+
If `context_check_stale` returns stale `current_*` keys:
|
|
102
|
+
1. Read the stale key contents
|
|
103
|
+
2. Ask user: "There's an unfinished [operation] — continue it or discard?"
|
|
104
|
+
3. If continue: resume the workflow from the summary step
|
|
105
|
+
4. If discard: call `context_clear_scratchpad` for that key, then proceed
|
|
@@ -209,3 +209,39 @@ export default App;
|
|
|
209
209
|
5. Wire form submit and button clicks to handler functions
|
|
210
210
|
6. Add loading state (boolean), error state (string), success state
|
|
211
211
|
7. Show loading spinner during API call, error message on failure, success feedback on completion
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Wave Generation Order (v4.0)
|
|
216
|
+
|
|
217
|
+
Wave 1 — Foundation (read `.codeninja/tasks/generate-react-package-json.task.md` etc.):
|
|
218
|
+
- `package.json` → task: generate-react-package-json
|
|
219
|
+
- `.env` + `.env.example` → task: generate-react-env
|
|
220
|
+
- `.gitignore` → task: generate-react-gitignore
|
|
221
|
+
- `README.md` → task: generate-readme
|
|
222
|
+
- `public/index.html` → task: generate-react-index-html
|
|
223
|
+
- `.htaccess` (root + public) → task: generate-react-htaccess
|
|
224
|
+
|
|
225
|
+
Wave 2 — API Layer:
|
|
226
|
+
- `src/api/apiClient.js` → task: generate-react-api-client
|
|
227
|
+
- `src/api/apiHandler.js` → task: generate-react-api-handler
|
|
228
|
+
|
|
229
|
+
Wave 3 — Application Shell:
|
|
230
|
+
- `src/pages/Welcome/index.jsx` → task: generate-react-welcome-page
|
|
231
|
+
- `src/App.jsx` → task: generate-react-app-jsx
|
|
232
|
+
- `src/index.jsx` → task: generate-react-index-jsx
|
|
233
|
+
|
|
234
|
+
Wave 4 — Docker:
|
|
235
|
+
- `Dockerfile` + `nginx.conf` → task: generate-react-dockerfile
|
|
236
|
+
|
|
237
|
+
## .htaccess Pattern
|
|
238
|
+
|
|
239
|
+
Two files are always generated — one at service root, one in `public/`:
|
|
240
|
+
|
|
241
|
+
```apache
|
|
242
|
+
RewriteEngine On
|
|
243
|
+
RewriteBase /
|
|
244
|
+
RewriteCond %{REQUEST_FILENAME} !-f
|
|
245
|
+
RewriteCond %{REQUEST_FILENAME} !-d
|
|
246
|
+
RewriteRule ^ index.html [L]
|
|
247
|
+
```
|
|
@@ -1,111 +1,104 @@
|
|
|
1
|
+
This workflow runs when user invokes /codeninja:api
|
|
2
|
+
|
|
1
3
|
---
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type: workflow
|
|
5
|
+
name: create-api
|
|
6
|
+
description: >
|
|
7
|
+
Add a new API module (route.js + model.js) to an existing NodeJS service.
|
|
8
|
+
Appends to route_manager.js and patches swagger_doc.json surgically —
|
|
9
|
+
never rewrites existing files. Fully context-aware.
|
|
6
10
|
---
|
|
7
11
|
|
|
8
|
-
#
|
|
12
|
+
# Workflow: @create-api
|
|
13
|
+
|
|
14
|
+
## Goal
|
|
15
|
+
Scaffold a complete API module inside an existing NodeJS service.
|
|
16
|
+
Every generated file references actual DB columns from context.
|
|
17
|
+
|
|
18
|
+
## Rules
|
|
19
|
+
- Ask ONE question at a time
|
|
20
|
+
- Never invent table or column names — read from `context.db.schema`
|
|
21
|
+
- Always add the new route to `context.api_routes`
|
|
22
|
+
- Always update `swagger_doc.json` with the new endpoint
|
|
9
23
|
|
|
10
|
-
|
|
11
|
-
1. Call `context_check_stale`
|
|
12
|
-
2. Call `context_read` — load `context.services` and `context.db.schema`
|
|
13
|
-
3. Read 1–2 existing modules in the target service to understand current patterns
|
|
24
|
+
---
|
|
14
25
|
|
|
15
|
-
##
|
|
26
|
+
## Step-by-Step Execution
|
|
16
27
|
|
|
17
28
|
### Phase 0 — Existing Pattern Review
|
|
18
|
-
Before asking any questions, read existing modules in
|
|
19
|
-
and scan 1–2 existing
|
|
29
|
+
Before asking any questions, read the existing modules in
|
|
30
|
+
context.services[<service_name>].modules and scan 1–2 existing
|
|
31
|
+
route.js and _model.js files from the service.
|
|
20
32
|
|
|
21
33
|
Identify:
|
|
22
|
-
- Naming conventions (camelCase vs PascalCase)
|
|
23
|
-
- Common validation patterns
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
Surface: "I've reviewed [n] existing modules. I'll follow the same structure." Then proceed.
|
|
34
|
+
- Naming conventions in use (camelCase vs PascalCase for functions)
|
|
35
|
+
- Common validation patterns (which fields always get required rules)
|
|
36
|
+
- Any project-specific response patterns beyond the standard contract
|
|
37
|
+
- Auth pattern used across existing routes (all full? mixed?)
|
|
28
38
|
|
|
29
|
-
|
|
39
|
+
Surface a one-line summary: "I've reviewed [n] existing modules.
|
|
40
|
+
I'll follow the same structure." Then proceed to Phase 1.
|
|
30
41
|
|
|
31
42
|
### Phase 1 — Target Service
|
|
43
|
+
1. Run task: `ask-target-service`
|
|
44
|
+
- List available services from `context.services`
|
|
45
|
+
- Stores: `context.current_api.service_name`
|
|
32
46
|
|
|
33
|
-
|
|
34
|
-
-
|
|
35
|
-
|
|
36
|
-
**Step 2.** Ask: "API version?" (default: v1)
|
|
37
|
-
- Store: `context.current_api.version`
|
|
47
|
+
2. Run task: `ask-api-version`
|
|
48
|
+
- Default: v1
|
|
49
|
+
- Stores: `context.current_api.version`
|
|
38
50
|
|
|
39
51
|
---
|
|
40
52
|
|
|
41
53
|
### Phase 2 — Module Identity
|
|
54
|
+
3. Run task: `ask-module-name`
|
|
55
|
+
- Example: Products, Orders, Invoice
|
|
56
|
+
- Stores: `context.current_api.module_name`
|
|
42
57
|
|
|
43
|
-
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
**Step 4.** Ask: "HTTP method?" (GET / POST / PUT / PATCH / DELETE)
|
|
47
|
-
- Store: `context.current_api.method`
|
|
58
|
+
4. Run task: `ask-http-method`
|
|
59
|
+
- Options: GET, POST, PUT, PATCH, DELETE
|
|
60
|
+
- Stores: `context.current_api.method`
|
|
48
61
|
|
|
49
|
-
|
|
50
|
-
-
|
|
62
|
+
5. Run task: `ask-route-path`
|
|
63
|
+
- Example: /products, /products/:id
|
|
64
|
+
- Stores: `context.current_api.route_path`
|
|
51
65
|
|
|
52
|
-
|
|
53
|
-
-
|
|
66
|
+
6. Run task: `ask-route-description`
|
|
67
|
+
- Stores: `context.current_api.description`
|
|
54
68
|
|
|
55
69
|
---
|
|
56
70
|
|
|
57
71
|
### Phase 3 — Database Binding
|
|
72
|
+
7. Run task: `ask-primary-table`
|
|
73
|
+
- Show available tables from `context.db.schema.tables`
|
|
74
|
+
- Stores: `context.current_api.primary_table`
|
|
58
75
|
|
|
59
|
-
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
**Step 8.** Ask: "Does this route require authentication?" (yes / no)
|
|
64
|
-
- Store: `context.current_api.requires_auth`
|
|
76
|
+
8. Run task: `ask-requires-auth`
|
|
77
|
+
- Options: yes / no
|
|
78
|
+
- Stores: `context.current_api.requires_auth`
|
|
65
79
|
|
|
66
80
|
---
|
|
67
81
|
|
|
68
|
-
### Phase 4 —
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
- Patch `document/<version>/swagger_doc.json`
|
|
92
|
-
- Use `file_insert_after` MCP tool — NEVER rewrite this file
|
|
93
|
-
- Add new path key to the `paths` object only
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
|
|
97
|
-
### Phase 5 — Finalize
|
|
98
|
-
|
|
99
|
-
**Step 11.** Call `context_write`:
|
|
100
|
-
- Append to `context.api_routes`
|
|
101
|
-
- Update `context.services[<service>].modules`
|
|
102
|
-
- Set `last_command` = "create-api"
|
|
103
|
-
- Append to `change_log`
|
|
104
|
-
|
|
105
|
-
**Step 12.** Call `context_clear_scratchpad` with keys: ["current_api"]
|
|
106
|
-
|
|
107
|
-
**Step 13.** Show final summary:
|
|
108
|
-
- Files created/modified
|
|
109
|
-
- Route registered in route_manager
|
|
110
|
-
- Swagger patched
|
|
111
|
-
- Offer next steps: /codeninja:design, /codeninja:db:create
|
|
82
|
+
### Phase 4 — Generate
|
|
83
|
+
9. Confirm with user: "Generate [METHOD] [path] in [service]/modules/[version]/[Module]? (yes/no)"
|
|
84
|
+
|
|
85
|
+
> **Multi-agent:** Delegate to `nodejs-backend` via Task invocation for parallel execution.
|
|
86
|
+
> Read `.codeninja/tasks/generate-route.task.md` and `.codeninja/tasks/generate-model.task.md` before generating each file.
|
|
87
|
+
|
|
88
|
+
10. Delegate to `nodejs-agent`:
|
|
89
|
+
- Generate: `route.js` — run task: generate-route
|
|
90
|
+
(new file — always a full write)
|
|
91
|
+
- Generate: `<module>_model.js` — run task: generate-model
|
|
92
|
+
(new file — always a full write)
|
|
93
|
+
- Append to: `modules/<version>/route_manager.js`
|
|
94
|
+
run task: generate-route-manager (Mode 2 — append only)
|
|
95
|
+
NEVER rewrite this file — surgical insert only
|
|
96
|
+
- Patch: `document/<version>/swagger_doc.json`
|
|
97
|
+
run task: generate-swagger (Mode 2 — patch paths object only)
|
|
98
|
+
NEVER rewrite this file — add new path key only
|
|
99
|
+
|
|
100
|
+
11. Run task: `write-context`
|
|
101
|
+
- Append to `context.api_routes`
|
|
102
|
+
- Update `context.services[<service>].modules`
|
|
103
|
+
|
|
104
|
+
12. Run task: `show-final-summary`
|
|
@@ -1,72 +1,110 @@
|
|
|
1
|
+
This workflow runs when user invokes /codeninja:audit
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
type: workflow
|
|
5
|
+
name: audit
|
|
6
|
+
description: >
|
|
7
|
+
Review an existing service for code quality, security issues, naming
|
|
8
|
+
consistency, missing middleware, and context alignment.
|
|
1
9
|
---
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
10
|
+
|
|
11
|
+
# Workflow: @audit
|
|
12
|
+
|
|
13
|
+
## Goal
|
|
14
|
+
Produce a structured audit report for a service. Identify issues by severity.
|
|
15
|
+
Optionally auto-fix low-risk issues.
|
|
16
|
+
|
|
17
|
+
## When to use @audit vs @sync drift detection
|
|
18
|
+
|
|
19
|
+
`@sync` drift detection: runs automatically with every @sync. Checks
|
|
20
|
+
structural markers only — middleware order, library consistency,
|
|
21
|
+
export patterns. Fast, read-only, always safe.
|
|
22
|
+
|
|
23
|
+
`@audit`: run manually when you want deep code quality analysis —
|
|
24
|
+
security checks, SQL injection patterns, response format consistency,
|
|
25
|
+
context alignment. Slower, comprehensive, covers logic not just structure.
|
|
26
|
+
|
|
27
|
+
Run @sync regularly. Run @audit before releasing a service or after
|
|
28
|
+
a major refactor.
|
|
29
|
+
|
|
6
30
|
---
|
|
7
31
|
|
|
8
|
-
|
|
32
|
+
## Step-by-Step Execution
|
|
9
33
|
|
|
10
|
-
|
|
11
|
-
1. Call `context_read`
|
|
12
|
-
2. Call `context_check_stale`
|
|
34
|
+
1. Run task: `ask-target-service`
|
|
13
35
|
|
|
14
|
-
|
|
36
|
+
> **Multi-agent:** Delegate to `nodejs-backend` or `database-architect` based on service type via Task invocation for parallel execution.
|
|
37
|
+
> Read `.codeninja/tasks/` task files relevant to the service before running checks.
|
|
15
38
|
|
|
16
|
-
|
|
39
|
+
2. Delegate to relevant agent(s) based on service type.
|
|
17
40
|
|
|
18
|
-
|
|
41
|
+
3. Agent checks:
|
|
19
42
|
|
|
20
43
|
### Security Checks
|
|
21
|
-
- [ ] API key validation middleware
|
|
44
|
+
- [ ] API key validation middleware applied to all routes?
|
|
22
45
|
- [ ] Input validation on all POST/PUT/PATCH routes?
|
|
23
|
-
- [ ] SQL injection prevention (parameterized queries
|
|
46
|
+
- [ ] SQL injection prevention (parameterized queries)?
|
|
24
47
|
- [ ] Sensitive values only from env vars (no hardcoded keys/passwords)?
|
|
25
48
|
- [ ] `.env` in `.gitignore`?
|
|
26
|
-
- [ ]
|
|
27
|
-
- [ ]
|
|
28
|
-
- [ ]
|
|
49
|
+
- [ ] Encryption using real AES-256-CBC (not base64)?
|
|
50
|
+
- [ ] utilities/encryption.js is the only file importing crypto-js or cryptlib?
|
|
51
|
+
- [ ] res.json() is never called directly in route.js or model files?
|
|
29
52
|
- [ ] Validator package never imported directly in route files?
|
|
30
|
-
- [ ] SMTP credentials only in .env — never hardcoded in
|
|
31
|
-
|
|
32
|
-
- [ ]
|
|
53
|
+
- [ ] SMTP credentials only in .env — never hardcoded in
|
|
54
|
+
notification.js or template.js?
|
|
55
|
+
- [ ] Firebase service account file in pem/ and in .gitignore?
|
|
56
|
+
- [ ] GLOBALS object is frozen using Object.freeze?
|
|
33
57
|
|
|
34
58
|
### Code Quality Checks
|
|
35
|
-
- [ ]
|
|
36
|
-
- [ ]
|
|
59
|
+
- [ ] Controllers only call services (no DB queries in controllers)?
|
|
60
|
+
- [ ] Services contain business logic (no Express req/res objects)?
|
|
61
|
+
- [ ] Models contain only DB queries?
|
|
37
62
|
- [ ] Global error handler present and used?
|
|
38
|
-
- [ ] All routes call
|
|
39
|
-
|
|
40
|
-
- [ ]
|
|
41
|
-
- [ ]
|
|
42
|
-
- [ ]
|
|
43
|
-
- [ ]
|
|
44
|
-
- [ ]
|
|
45
|
-
- [ ]
|
|
46
|
-
- [ ]
|
|
47
|
-
|
|
48
|
-
- [ ]
|
|
63
|
+
- [ ] All routes call checkValidationRules from utilities/validator.js
|
|
64
|
+
before calling model functions?
|
|
65
|
+
- [ ] No separate _validator.js files exist per module?
|
|
66
|
+
- [ ] rateLimiter is the first middleware in route_manager.js?
|
|
67
|
+
- [ ] extractLanguage runs before validateApiKey in route_manager.js?
|
|
68
|
+
- [ ] decryptRequest is the last middleware in the chain?
|
|
69
|
+
- [ ] No route handlers defined directly in route_manager.js?
|
|
70
|
+
- [ ] asyncHandler wraps every middleware in route_manager.js?
|
|
71
|
+
- [ ] All model functions return exactly { responsecode, responsemsg,
|
|
72
|
+
responsedata } — no extra keys, no throws?
|
|
73
|
+
- [ ] No req/res objects in any model file?
|
|
74
|
+
- [ ] Passwords HASHED (not encrypted) using `utilities/hashing.js` before storage?
|
|
75
|
+
Correct: `await hashPassword(plainText)` — one-way bcrypt/argon2 hash
|
|
76
|
+
Wrong: `encrypt(password)` from encryption.js — reversible AES, not safe for passwords
|
|
77
|
+
- [ ] No direct bcrypt/argon2 imports in route.js or model files? All hashing routed through utilities/hashing.js?
|
|
78
|
+
- [ ] Session tokens generated only via common.generateSessionCode?
|
|
79
|
+
- [ ] No crypto-js or cryptlib imported directly in model files?
|
|
80
|
+
- [ ] No direct res.json() calls in route.js files?
|
|
49
81
|
|
|
50
82
|
### Consistency Checks
|
|
51
83
|
- [ ] All routes documented in `swagger_doc.json`?
|
|
52
84
|
- [ ] Response format consistent (success, message, data, timestamp)?
|
|
53
|
-
- [ ] snake_case for DB, camelCase for JS?
|
|
54
|
-
- [ ] Port matches `context.services[<
|
|
85
|
+
- [ ] Naming follows snake_case for DB, camelCase for JS?
|
|
86
|
+
- [ ] Port matches `context.services[<name>].port`?
|
|
55
87
|
- [ ] DB config matches `context.db`?
|
|
56
|
-
- [ ] All message keywords in
|
|
57
|
-
|
|
88
|
+
- [ ] All message keywords used in sendResponse calls exist in
|
|
89
|
+
languages/en.js?
|
|
90
|
+
- [ ] All language files contain the same set of keys as en.js?
|
|
58
91
|
- [ ] No two services share the same port in context.services?
|
|
59
|
-
- [ ] All encryption keys
|
|
60
|
-
- [ ] All encryption IVs
|
|
92
|
+
- [ ] All encryption keys in context.services are exactly 32 characters?
|
|
93
|
+
- [ ] All encryption IVs in context.services are exactly 16 characters?
|
|
94
|
+
- [ ] No service name in context.services conflicts with a folder name
|
|
95
|
+
that already exists on disk for a different service?
|
|
61
96
|
|
|
62
97
|
### Context Alignment
|
|
63
98
|
- [ ] All routes present in `context.api_routes`?
|
|
64
99
|
- [ ] All DB tables referenced match `context.db.schema`?
|
|
65
|
-
- [ ] All
|
|
66
|
-
|
|
67
|
-
- [ ] All
|
|
100
|
+
- [ ] All router.use() lines in route_manager.js have a corresponding
|
|
101
|
+
entry in context.services[<name>].modules?
|
|
102
|
+
- [ ] All context.services[<name>].modules entries have a corresponding
|
|
103
|
+
router.use() line in route_manager.js?
|
|
104
|
+
- [ ] All paths in swagger_doc.json have a corresponding entry in
|
|
105
|
+
context.api_routes?
|
|
68
106
|
|
|
69
|
-
|
|
107
|
+
4. Present audit report:
|
|
70
108
|
```
|
|
71
109
|
AUDIT REPORT — <service_name>
|
|
72
110
|
══════════════════════════════════════
|
|
@@ -77,5 +115,5 @@ AUDIT REPORT — <service_name>
|
|
|
77
115
|
[list findings with file + line context]
|
|
78
116
|
```
|
|
79
117
|
|
|
80
|
-
|
|
81
|
-
If yes → delegate to
|
|
118
|
+
5. Ask: "Auto-fix critical issues? (yes/no)"
|
|
119
|
+
6. If yes → delegate to relevant agent for fixes → run task: `write-context`
|