codeninja 3.1.0 → 4.0.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.
Files changed (111) hide show
  1. package/README.md +13 -1
  2. package/agent/database-agent.md +24 -1
  3. package/agent/nodejs-agent.md +79 -0
  4. package/cli.js +27 -7
  5. package/commands/audit.workflow.md +4 -1
  6. package/commands/db-create-table.workflow.md +1 -1
  7. package/commands/initialize-project.workflow.md +21 -0
  8. package/ide/antigravity/.agents/personas/database-architect.md +431 -153
  9. package/ide/antigravity/.agents/personas/global-orchestrator.md +219 -83
  10. package/ide/antigravity/.agents/personas/nodejs-backend.md +368 -133
  11. package/ide/antigravity/.agents/personas/reactjs-frontend.md +182 -101
  12. package/ide/antigravity/.agents/skills/api-builder/SKILL.md +58 -0
  13. package/ide/antigravity/.agents/skills/code-intelligence/SKILL.md +22 -0
  14. package/ide/antigravity/.agents/skills/database/SKILL.md +32 -0
  15. package/ide/antigravity/.agents/skills/mcp-and-context/SKILL.md +76 -82
  16. package/ide/antigravity/.agents/skills/reactjs/SKILL.md +36 -0
  17. package/ide/antigravity/.agents/workflows/codeninja-api.md +97 -21
  18. package/ide/antigravity/.agents/workflows/codeninja-audit.md +112 -16
  19. package/ide/antigravity/.agents/workflows/codeninja-db-create.md +135 -9
  20. package/ide/antigravity/.agents/workflows/codeninja-db-drop.md +107 -9
  21. package/ide/antigravity/.agents/workflows/codeninja-db-index.md +100 -9
  22. package/ide/antigravity/.agents/workflows/codeninja-db-modify.md +162 -9
  23. package/ide/antigravity/.agents/workflows/codeninja-db-seed.md +102 -8
  24. package/ide/antigravity/.agents/workflows/codeninja-db-sync.md +105 -11
  25. package/ide/antigravity/.agents/workflows/codeninja-debug.md +94 -10
  26. package/ide/antigravity/.agents/workflows/codeninja-design.md +61 -14
  27. package/ide/antigravity/.agents/workflows/codeninja-explain.md +59 -9
  28. package/ide/antigravity/.agents/workflows/codeninja-init.md +518 -21
  29. package/ide/antigravity/.agents/workflows/codeninja-integrate-api.md +451 -9
  30. package/ide/antigravity/.agents/workflows/codeninja-modularize.md +332 -9
  31. package/ide/antigravity/.agents/workflows/codeninja-optimize.md +124 -11
  32. package/ide/antigravity/.agents/workflows/codeninja-refactor.md +69 -16
  33. package/ide/antigravity/.agents/workflows/codeninja-review.md +85 -10
  34. package/ide/antigravity/.agents/workflows/codeninja-sync.md +957 -16
  35. package/ide/antigravity/.agents/workflows/codeninja-test.md +40 -13
  36. package/ide/antigravity/.agents/workflows/codeninja-validate-page.md +546 -9
  37. package/ide/claude-code/.claude/CLAUDE.md +99 -0
  38. package/ide/claude-code/.claude/agents/database-agent.md +535 -0
  39. package/ide/claude-code/.claude/agents/nodejs-agent.md +493 -0
  40. package/ide/claude-code/.claude/agents/reactjs-agent.md +267 -0
  41. package/ide/claude-code/.claude/commands/codeninja-api.md +104 -0
  42. package/ide/claude-code/.claude/commands/codeninja-audit.md +119 -0
  43. package/ide/claude-code/.claude/commands/codeninja-db-create.md +138 -0
  44. package/ide/claude-code/.claude/commands/codeninja-db-drop.md +109 -0
  45. package/ide/claude-code/.claude/commands/codeninja-db-index.md +103 -0
  46. package/ide/claude-code/.claude/commands/codeninja-db-modify.md +165 -0
  47. package/ide/claude-code/.claude/commands/codeninja-db-seed.md +104 -0
  48. package/ide/claude-code/.claude/commands/codeninja-db-sync.md +106 -0
  49. package/ide/claude-code/.claude/commands/codeninja-debug.md +99 -0
  50. package/ide/claude-code/.claude/commands/codeninja-design.md +68 -0
  51. package/ide/claude-code/.claude/commands/codeninja-explain.md +61 -0
  52. package/ide/claude-code/.claude/commands/codeninja-init.md +529 -0
  53. package/ide/claude-code/.claude/commands/codeninja-integrate-api.md +453 -0
  54. package/ide/claude-code/.claude/commands/codeninja-modularize.md +334 -0
  55. package/ide/claude-code/.claude/commands/codeninja-optimize.md +129 -0
  56. package/ide/claude-code/.claude/commands/codeninja-refactor.md +76 -0
  57. package/ide/claude-code/.claude/commands/codeninja-review.md +87 -0
  58. package/ide/claude-code/.claude/commands/codeninja-sync.md +964 -0
  59. package/ide/claude-code/.claude/commands/codeninja-test.md +45 -0
  60. package/ide/claude-code/.claude/commands/codeninja-validate-page.md +548 -0
  61. package/ide/cursor/.cursor/rules/01-global-orchestrator.mdc +40 -38
  62. package/ide/cursor/.cursor/rules/02-mcp-and-context.mdc +47 -31
  63. package/ide/cursor/.cursor/rules/03-api-builder.mdc +30 -58
  64. package/ide/cursor/.cursor/rules/04-nodejs-generation.mdc +58 -0
  65. package/ide/cursor/.cursor/rules/05-database.mdc +54 -0
  66. package/ide/cursor/.cursor/rules/06-reactjs.mdc +36 -0
  67. package/ide/cursor/.cursor/rules/07-reactjs-generation.mdc +49 -0
  68. package/ide/cursor/.cursor/rules/08-code-intelligence.mdc +56 -0
  69. package/ide/cursor/.cursor/rules/09-workflow-steps.mdc +53 -0
  70. package/ide/vscode/.github/copilot-instructions.md +69 -270
  71. package/ide/vscode/.vscode/instructions/code-intelligence.instructions.md +58 -0
  72. package/ide/vscode/.vscode/instructions/database.instructions.md +55 -0
  73. package/ide/vscode/.vscode/instructions/nodejs.instructions.md +77 -0
  74. package/ide/vscode/.vscode/instructions/reactjs.instructions.md +42 -0
  75. package/package.json +2 -2
  76. package/tasks/ask-hashing-library.task.md +31 -0
  77. package/tasks/ask-language-type.task.md +26 -0
  78. package/tasks/ask-new-module-name.task.md +13 -0
  79. package/tasks/ask-new-service-name.task.md +13 -0
  80. package/tasks/ask-old-module-name.task.md +15 -0
  81. package/tasks/ask-old-service-name.task.md +13 -0
  82. package/tasks/ask-orm-type.task.md +26 -0
  83. package/tasks/collect-seed-data.task.md +19 -0
  84. package/tasks/generate-app.task.md +42 -0
  85. package/tasks/generate-common.task.md +13 -0
  86. package/tasks/generate-constants.task.md +13 -0
  87. package/tasks/generate-database.task.md +32 -0
  88. package/tasks/generate-encryption.task.md +28 -0
  89. package/tasks/generate-fast-defaults.task.md +7 -0
  90. package/tasks/generate-hashing.task.md +180 -0
  91. package/tasks/generate-headerValidator.task.md +13 -0
  92. package/tasks/generate-ioRedis.task.md +20 -0
  93. package/tasks/generate-language-en.task.md +12 -0
  94. package/tasks/generate-logging.task.md +12 -0
  95. package/tasks/generate-model.task.md +74 -6
  96. package/tasks/generate-notification.task.md +12 -0
  97. package/tasks/generate-package-json.task.md +69 -0
  98. package/tasks/generate-prisma-client.task.md +56 -0
  99. package/tasks/generate-prisma-schema.task.md +71 -0
  100. package/tasks/generate-rateLimiter.task.md +20 -0
  101. package/tasks/generate-readme.task.md +24 -0
  102. package/tasks/generate-response.task.md +27 -0
  103. package/tasks/generate-route-manager.task.md +32 -0
  104. package/tasks/generate-route.task.md +37 -0
  105. package/tasks/generate-swagger.task.md +8 -0
  106. package/tasks/generate-template.task.md +12 -0
  107. package/tasks/generate-tsconfig.task.md +38 -0
  108. package/tasks/generate-validator.task.md +31 -0
  109. package/ide/cursor/.cursor/rules/04-database.mdc +0 -87
  110. package/ide/cursor/.cursor/rules/05-reactjs.mdc +0 -83
  111. package/ide/cursor/.cursor/rules/06-code-intelligence.mdc +0 -112
@@ -1,285 +1,84 @@
1
- # codeninja — Project Intelligence for GitHub Copilot
1
+ # codeninja — Project Intelligence for GitHub Copilot (v4.0)
2
2
 
3
3
  This file is auto-loaded by GitHub Copilot Agent Mode.
4
- It gives Copilot full awareness of this project's architecture, conventions,
5
- and all available slash commands.
6
4
 
7
5
  ---
8
6
 
9
- ## Section 1 Global Orchestrator
10
-
11
- You are a Senior Software Architect managing this project via the codeninja system.
12
-
13
- ### Activation Sequence (every session)
7
+ ## Activation Sequence (every session)
14
8
  1. Call `context_check_stale` — resolve stale operations first
15
- 2. Call `context_read` — load full context
16
- 3. Call `service_scan` — compare with `context.services`; suggest `/codeninja:sync` if drift
17
- 4. Load `context.project_info` for all suggestions
18
-
19
- ### Routing
20
- | Keyword trigger | Specialist domain |
21
- |----------------|------------------|
22
- | express, node, api, service, encryption | API Builder |
23
- | react, frontend, ui, component | ReactJS |
24
- | postgres, mysql, db, schema, migration, table | Database |
25
- | `/codeninja:db:*` | always Database |
9
+ 2. Call `context_read` — load full project context
10
+ 3. Call `service_scan` — compare with `context.services`; if drift → suggest `/codeninja:sync`
11
+ 4. Load `context.project_info` — use for all suggestions throughout session
26
12
 
27
- ### Context Rules
28
- - NEVER read/write `context.json` directly — always `context_read` / `context_write`
29
- - `context_write` deep-merges — never overwrites the whole file
13
+ ## Context Rules
14
+ - NEVER read/write context.json directly — always `context_read` / `context_write`
15
+ - `context_write` deep-merges — never overwrites
30
16
  - `change_log` is append-only
17
+ - After every completed workflow → call `context_clear_scratchpad` for relevant `current_*` key
31
18
 
32
- ### Batch Generation Rule
33
- ONE confirmation per operation. After user confirms → generate all files silently.
34
- No per-file prompts during `@init`, `@api`, or `@db:create`.
19
+ ## Keyword Routing
20
+ | Trigger | Specialist Domain |
21
+ |---|---|
22
+ | express, node, api, service, encryption, typescript | NodeJS standards |
23
+ | react, frontend, ui, component, page | ReactJS standards |
24
+ | postgres, mysql, db, schema, migration, table, prisma, orm | Database standards |
25
+ | `/codeninja:db:*` | always Database standards |
35
26
 
36
- ### Response Style
37
- - One question at a time
38
- - Always confirm before creating or modifying files
39
- - `database/` folder ALWAYS at repository root — never inside a service folder
40
- - After scaffolding → always run task: `show-final-summary`
27
+ ## Batch Generation Rule
28
+ ONE confirmation per operation generate ALL files silently after confirmation, no per-file prompts.
41
29
 
42
- ---
43
-
44
- ## Section 2 MCP Tools and Context
30
+ ## Response Style
31
+ - One question at a time
32
+ - Confirm before creating or modifying files
33
+ - `database/` folder ALWAYS at repository root
34
+ - After every scaffolding operation → show final summary
45
35
 
46
- ### Available MCP Tools
36
+ ## All Available Commands
37
+ | Command | Description |
38
+ |---|---|
39
+ | `/codeninja:init` | Bootstrap NodeJS service (JS/TS, raw/Prisma), ReactJS app, or database |
40
+ | `/codeninja:api` | Add new API endpoint (route + model + swagger) |
41
+ | `/codeninja:design` | Plan feature before coding |
42
+ | `/codeninja:audit` | Security and quality review |
43
+ | `/codeninja:test` | Generate Jest + Supertest tests |
44
+ | `/codeninja:refactor` | Rename/restructure with context tracking |
45
+ | `/codeninja:sync` | Rebuild context.json from repo |
46
+ | `/codeninja:explain` | Explain any file, function, or concept |
47
+ | `/codeninja:review` | Code review with severity-ranked findings |
48
+ | `/codeninja:debug` | Diagnose and fix bugs |
49
+ | `/codeninja:optimize` | Performance analysis with concrete fixes |
50
+ | `/codeninja:db:create` | New table with migration file |
51
+ | `/codeninja:db:modify` | Alter table via migration |
52
+ | `/codeninja:db:index` | Add index |
53
+ | `/codeninja:db:drop` | Drop table (safety-checked) |
54
+ | `/codeninja:db:seed` | Add seed data |
55
+ | `/codeninja:db:sync` | Rebuild DB schema context from migrations |
56
+ | `/codeninja:modularize` | Extract ReactJS layout components |
57
+ | `/codeninja:validate-page` | Add form validation to ReactJS page |
58
+ | `/codeninja:integrate-api` | Wire ReactJS forms to backend |
59
+
60
+ ## MCP Tools Quick Reference
47
61
  | Tool | Purpose | When |
48
- |------|---------|------|
49
- | `context_read` | Load project context | FIRST on every activation |
50
- | `context_write` | Persist changes (deep-merge) | After every completed operation |
62
+ |---|---|---|
63
+ | `context_read` | Load context.json | First on every activation |
64
+ | `context_write` | Deep-merge updates | After every completed operation |
51
65
  | `context_clear_scratchpad` | Clear current_* key | After writing context |
52
- | `context_check_stale` | Detect unresolved scratchpad | Step 0 of activation |
53
- | `service_scan` | Discover all services on disk | Step 2 of activation |
54
- | `migration_next_number` | Next sequential migration number | Before any migration file |
55
- | `fs_read` | Read file from disk | Before modifying |
56
- | `fs_list` | List directory | When scanning structure |
57
- | `fs_exists` | Check existence | Before conditional ops |
58
- | `file_insert_after` | Surgical file insertion | route_manager.js, swagger |
59
- | `file_contains` | Check before appending | Avoid duplicates |
60
- | `run_drift_check` | Context vs disk | During @sync |
61
- | `lint_file` | Lint generated file | After JS/SQL generation |
62
- | `analyze_middleware_order` | Check middleware chain | During @audit |
63
- | `analyze_encryption_library` | Verify encryption | During @audit |
64
- | `analyze_language_keys` | Check i18n | During @audit |
65
- | `analyze_dependencies` | Scan package.json | During @audit |
66
- | `analyze_env_file` | Check .env completeness | During @audit |
67
- | `validate_redis_connection` | Test Redis | During init |
68
- | `validate_postgres_connection` | Test DB | During init |
69
-
70
- ---
71
-
72
- ## Section 3 — API Builder (NodeJS/Express)
73
-
74
- ### 2-Layer Architecture (enforced)
75
- ```
76
- modules/v1/<ModuleName>/
77
- ├── route.js ← HTTP only: validation, middleware, res.json()
78
- └── <module>_model.js ← DB only: queries, business logic
79
- ```
80
- Never SQL in `route.js`. Never `res.json()` in `_model.js`.
81
-
82
- ### 5-Step SOP for New Endpoints
83
- 1. **ROUTING** — append to `route_manager.js` via `file_insert_after` (never rewrite)
84
- 2. **VALIDATION** — validatorjs schema in `route.js`, match existing patterns
85
- 3. **CONTROLLER** — model call + try/catch + `sendResponse()` in `route.js`
86
- 4. **MODEL** — parameterized `$1,$2` SQL via pg pool in `_model.js`
87
- 5. **LOCALIZE** — all strings in `languages/en.js`, check with `file_contains` first
88
-
89
- ### Middleware Chain Order
90
- Language extraction → API key validation → JWT auth (protected only) → Rate limiting → Validation → Handler
91
-
92
- ### Response Contract
93
- ```javascript
94
- { status: 1, message: lang.key, data: result } // success
95
- { status: 0, message: lang.key } // error
96
- { status: -1, message: lang.key } // session expired
97
- ```
98
- Always `sendResponse(req, res, status, message, data)`. Never `res.json()` directly.
99
-
100
- ### Localizify Rules
101
- Only `headerValidator.js` and `response.js` may import localizify or call `t()`.
102
- All other files use `sendResponse()`, `getMessage()`, or `req.t("key")`.
103
-
104
- ### Encryption Selection
105
- | client_type | Library | Demo file |
106
- |-------------|---------|-----------|
107
- | `reactjs` | crypto-js AES-256-CBC | enc_dec.html |
108
- | `app` | cryptlib AES-256-CBC | enc_dec.php |
109
- `encrypted_transport: true` → encrypt full response payload.
110
- KEY/IV always from context — never hardcode.
111
-
112
- ### Service File Structure
113
- ```
114
- <service>/
115
- app.js, .env, .env.example, .gitignore, README.md, package.json
116
- config/ common.js, constants.js, database.js, template.js
117
- languages/ <lang>.js (one per supported_languages[])
118
- logger/ logging.js, logs/ (gitignored)
119
- middleware/ headerValidator.js, rateLimiter.js
120
- modules/v1/ route_manager.js, <ModuleName>/route.js + <m>_model.js
121
- utilities/ encryption.js, response.js, validator.js, ioRedis.js, notification.js
122
- document/v1/ swagger_doc.json
123
- tests/v1/ <ModuleName>.test.js
124
- pem/ (gitignored), images/ (gitignored)
125
- ```
126
-
127
- ### JSDoc Standard
128
- ```javascript
129
- /**
130
- * One-sentence description. Active voice.
131
- * @param {type} name - Description.
132
- * @returns {Promise<Object>} Description.
133
- */
134
- ```
135
- Middleware: `@middleware` tag, no `@returns`. Route: `// POST /path — Business purpose.`
136
- No inline `//` inside function bodies. No file-level headers.
137
-
138
- ---
139
-
140
- ## Section 4 — Database Architect
141
-
142
- ### Before Any SQL File
143
- Call `migration_next_number`. Load `context.db` fully. `database/` always at repo root.
144
-
145
- ### Naming Conventions (strict)
146
- | Element | Rule | Example |
147
- |---------|------|---------|
148
- | Table | `tbl_` prefix, lowercase, plural | `tbl_users` |
149
- | Column | lowercase snake_case | `user_id`, `created_at` |
150
- | PK | `id` bigint identity, first column | always |
151
- | FK | `<table_singular_no_prefix>_id` | `user_id` refs `tbl_users` |
152
- | Create file | `<N>-setup-tbl-<n>.sql` | `3-setup-tbl-users.sql` |
153
- | Alter file | `<N>-alter-tbl-<n>-<desc>.sql` | `12-alter-tbl-users-add-kyc.sql` |
154
- | Drop file | `<N>-drop-tbl-<n>.sql` | `13-drop-tbl-sessions.sql` |
155
- | Shared indexes | `111-setup-database-indexes.sql` | always last |
156
-
157
- ### Primary Key (exact)
158
- ```sql
159
- id bigint NOT NULL GENERATED ALWAYS AS IDENTITY (INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1),
160
- ```
161
- `PRIMARY KEY (id)` at END of column block — never inline.
162
-
163
- ### Column Types
164
- `BIGINT NOT NULL DEFAULT 0` (FK) · `VARCHAR(132)` (email) · `TEXT` (token/password)
165
- `TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP` · `BOOLEAN NOT NULL DEFAULT FALSE`
166
- `INTEGER NOT NULL DEFAULT 0 CHECK (status IN (0,1))` · `NUMERIC(18,8)` (financial)
167
- `JSON NOT NULL DEFAULT '{}'` · NEVER PostgreSQL ENUM — always `VARCHAR + CHECK`
168
-
169
- ### SQL File Content Order
66
+ | `context_check_stale` | Detect unresolved ops | Step 0 of activation |
67
+ | `service_scan` | Discover services on disk | Step 2 of activation |
68
+ | `migration_next_number` | Next sequential migration # | Before any migration file |
69
+ | `file_insert_after` | Surgical insert | route_manager, swagger never rewrite |
70
+ | `file_contains` | Check for string | Before appending |
71
+ | `lint_file` | Lint generated JS/TS | After generation |
72
+
73
+ ## MCP Server Setup
74
+ Add to your VS Code MCP settings:
75
+ ```json
76
+ {
77
+ "mcpServers": {
78
+ "codeninja": {
79
+ "command": "node",
80
+ "args": ["${workspaceFolder}/.codeninja/mcp-server.js"]
81
+ }
82
+ }
83
+ }
170
84
  ```
171
- 1. Comment header
172
- 2. DROP TABLE IF EXISTS CASCADE
173
- 3. CREATE TABLE (id first, timestamps last)
174
- 4. COMMENT ON COLUMN (every enum/flag)
175
- 5. Per-table CREATE INDEX
176
- 6. ALTER TABLE OWNER TO <context.db.user>
177
- 7. GRANT ALL ON TABLE TO <context.db.user>
178
- 8. INSERT seed (reference tables only)
179
- ```
180
-
181
- ### Required Columns
182
- `id` + `created_at` on every table. `status` + `is_deleted` on entity tables. NOT on log/pivot tables.
183
-
184
- ### Index Rules
185
- Always index: every FK, `(status,is_deleted)` compound, `created_at DESC` on logs, `email+is_deleted` compound on users, any WHERE/ORDER BY column.
186
-
187
- ### create-schema.sql
188
- At `<repo_root>/database/<db_type>/create-schema.sql`. Auto-generated. `\i` entries in numeric order. `111-setup-database-indexes.sql` always last. Update after every table operation.
189
-
190
- ---
191
-
192
- ## Section 5 — ReactJS Frontend
193
-
194
- ### Backend Linking (enforced)
195
- Inherit from `context.services[linked]`: `port` → `REACT_APP_BASE_URL`, `encryption_key` → `REACT_APP_KEY`, `encryption_iv` → `REACT_APP_IV`, `api_key` → `REACT_APP_API_KEY`.
196
- NEVER ask user for these. NEVER hardcode.
197
-
198
- ### File Structure
199
- ```
200
- <service>/public/assets/css/style.css index.html .htaccess
201
- src/api/apiClient.js apiHandler.js
202
- src/components/ src/pages/Welcome/index.jsx App.jsx index.jsx
203
- .env (gitignored) .env.example package.json
204
- ```
205
-
206
- ### apiClient.js — 4 Responsibilities
207
- 1. Static headers: `api-key`, `Accept-Language`, `Content-Type: text/plain`
208
- 2. Request: encrypt body; attach encrypted `token` from `localStorage('wa_token')`
209
- 3. Response success: decrypt; parse JSON; `status === -1` → logout
210
- 4. Response error: `ERR_NETWORK` or `401` → logout + error message
211
-
212
- KEY/IV via `CryptoJS.enc.Hex.parse(process.env.REACT_APP_KEY/IV)`.
213
-
214
- ### apiHandler.js
215
- One async function per endpoint. No try/catch, no decryption. Session saving in handler.
216
-
217
- ### Code Style
218
- Functional components only. JSDoc on every export. `.module.css` per page. No `console.log`. No hardcoded API paths.
219
-
220
- ---
221
-
222
- ## Section 6 — Code Intelligence
223
-
224
- ### /codeninja:explain
225
- What it is → How it works → Why this way → Where it connects.
226
- Use real names from context throughout.
227
-
228
- ### /codeninja:review
229
- CRITICAL (security): missing validation, missing apiKey middleware, hardcoded secrets, string SQL concatenation.
230
- WARNING (architecture): SQL in route.js, res.json() in model.js, strings hardcoded.
231
- SUGGESTION (quality): missing JSDoc, console.log, SELECT *.
232
- Output: `[LEVEL] File: path Issue/Before/After/Why`
233
-
234
- ### /codeninja:debug
235
- Trace: Language → API key → JWT → Rate limit → Validation → Handler → Model → DB → Response.
236
- Check: column names vs context.db.schema, middleware order, missing try/catch, RANK vs DENSE_RANK.
237
- Output: root cause + before/after fix. Confirm before applying.
238
-
239
- ### /codeninja:optimize
240
- DB: missing indexes (vs context.db.schema), SELECT *, N+1, no LIMIT, RANK() gaps, DATE() in WHERE, duplicate rows.
241
- Output: `[HIGH|MED|LOW]` Target/Cause/Fix/Gain. Generate migration for new indexes.
242
-
243
- ### /codeninja:audit
244
- Full review + `analyze_middleware_order`, `analyze_encryption_library`, `analyze_language_keys`, `analyze_dependencies`, `analyze_env_file` MCP tools.
245
-
246
- ---
247
-
248
- ## Slash Commands Quick Reference
249
-
250
- Use with `@workspace` in Copilot Chat:
251
-
252
- | Command | Description |
253
- |---------|-------------|
254
- | `@workspace /codeninja:init` | Bootstrap NodeJS service, ReactJS app, or database |
255
- | `@workspace /codeninja:api` | Add API endpoint (5-step SOP) |
256
- | `@workspace /codeninja:design` | Plan feature before coding |
257
- | `@workspace /codeninja:audit` | Security and quality review |
258
- | `@workspace /codeninja:test` | Generate Jest tests |
259
- | `@workspace /codeninja:refactor` | Rename with context tracking |
260
- | `@workspace /codeninja:sync` | Rebuild context from repo |
261
- | `@workspace /codeninja:explain` | Explain any file or pattern |
262
- | `@workspace /codeninja:review` | Code review with findings |
263
- | `@workspace /codeninja:debug` | Debug with code path trace |
264
- | `@workspace /codeninja:optimize` | Performance improvements |
265
- | `@workspace /codeninja:db:create` | New table + migration |
266
- | `@workspace /codeninja:db:modify` | Alter column |
267
- | `@workspace /codeninja:db:index` | Add index |
268
- | `@workspace /codeninja:db:drop` | Drop table |
269
- | `@workspace /codeninja:db:seed` | Add seed data |
270
- | `@workspace /codeninja:db:sync` | Rebuild DB schema |
271
- | `@workspace @modularize` | Extract React layout components |
272
- | `@workspace @validate-page` | Add form validation |
273
- | `@workspace @integrate-api` | Wire forms to API handlers |
274
-
275
- ---
276
-
277
- ## File Locations
278
-
279
- | What | Path |
280
- |------|------|
281
- | Agent personas | `.codeninja/agent/` |
282
- | Workflow files | `.codeninja/commands/` |
283
- | Task files | `.codeninja/tasks/` |
284
- | Context | `.codeninja/context/context.json` |
285
- | MCP server | `.codeninja/mcp-server.js` |
@@ -0,0 +1,58 @@
1
+ ---
2
+ applyTo: "**/*"
3
+ ---
4
+
5
+ # codeninja — Code Intelligence Standards (v4.0)
6
+
7
+ ## /codeninja:audit Checklist
8
+
9
+ ### Security
10
+ - [ ] Passwords HASHED using `utilities/hashing.js` (bcrypt/argon2)? Not AES-encrypted?
11
+ - [ ] No direct bcrypt/argon2 imports in route/model files?
12
+ - [ ] Parameterized queries only — no string concatenation in SQL?
13
+ - [ ] API key validation on all routes?
14
+ - [ ] No hardcoded secrets in source?
15
+ - [ ] Middleware order: rateLimiter→extractLanguage→validateApiKey→[auth]→decryptRequest?
16
+
17
+ ### Architecture
18
+ - [ ] 2-layer rule enforced (no SQL in route, no res.json in model)?
19
+ - [ ] route_manager.js never fully rewritten (append-only via file_insert_after)?
20
+ - [ ] All routes in swagger_doc.json and context.api_routes?
21
+
22
+ ### v4.0 Checks
23
+ - [ ] orm="prisma": no `new PrismaClient()` in model files?
24
+ - [ ] language="typescript": all .ts files use import/export syntax?
25
+
26
+ ## /codeninja:debug Trace Path
27
+ 1. extractLanguage — Accept-Language header processed?
28
+ 2. validateApiKey — api-key header matches .env API_KEY?
29
+ 3. validateAuthToken (protected only) — JWT valid and not expired?
30
+ 4. rateLimiter — request not throttled?
31
+ 5. validatorjs rules — all required fields in request body?
32
+ 6. Model call — DB connection alive?
33
+ 7. Query — column names match context.db.schema?
34
+ 8. sendResponse — encrypted_transport handled?
35
+
36
+ **401:** middleware order or key mismatch | **400:** validation rules | **500:** DB/column issue
37
+
38
+ ## /codeninja:review Dimensions
39
+ - Security: auth middleware, parameterized queries, no hardcoded secrets, hashing not encryption
40
+ - Architecture: 2-layer rule, route_manager append-only, swagger/context coverage
41
+ - Code quality: JSDoc on all functions, no console.log, async try/catch
42
+ - Database: column names match context, FK indexes, LIMIT on list queries
43
+
44
+ ## /codeninja:optimize Patterns (ranked)
45
+ 1. Missing index → `CREATE INDEX CONCURRENTLY` (no table lock)
46
+ 2. `SELECT *` → explicit column list
47
+ 3. N+1 query → JOIN or IN clause
48
+ 4. `DATE(col)` in WHERE → range filter to use index
49
+ 5. `RANK()` with gaps → `DENSE_RANK()` for leaderboards
50
+ 6. Unbounded list query → add `LIMIT` and `OFFSET`
51
+ 7. Repeated identical queries → Redis cache opportunity
52
+ 8. `work_mem` for sort-heavy queries
53
+
54
+ ## /codeninja:refactor Types
55
+ - Rename DB column: ALTER migration + update model queries + context.change_log
56
+ - Rename service: update context.services key + context.change_log
57
+ - Rename table: ALTER migration + update all model references + context.change_log
58
+ - Rename module: rename files + update route_manager + context.change_log
@@ -0,0 +1,55 @@
1
+ ---
2
+ applyTo: "**/*.sql,**/database/**,**/prisma/**"
3
+ ---
4
+
5
+ # codeninja — Database Standards (v4.0)
6
+
7
+ ## Naming Conventions
8
+ | Element | Rule | Example |
9
+ |---|---|---|
10
+ | Table | `tbl_` prefix, lowercase, plural | `tbl_users` |
11
+ | Column | lowercase snake_case | `user_id`, `created_at` |
12
+ | PK | `id`, bigint identity, first column | always |
13
+ | FK | `<ref_table_singular_no_tbl>_id` | `user_id` refs `tbl_users` |
14
+ | Index (per-table) | `idx_<table_no_tbl>_<cols>` | `idx_users_email` |
15
+ | Shared indexes | `111-setup-database-indexes.sql` | always last file |
16
+
17
+ ## Column Types
18
+ | Use Case | PostgreSQL Type |
19
+ |---|---|
20
+ | PK | `bigint NOT NULL GENERATED ALWAYS AS IDENTITY (INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1)` |
21
+ | FK | `BIGINT NOT NULL DEFAULT 0` |
22
+ | Email | `VARCHAR(132) NOT NULL DEFAULT ''` |
23
+ | Password/token | `TEXT NOT NULL DEFAULT ''` |
24
+ | Status | `INTEGER NOT NULL DEFAULT 0 CHECK (status IN (0, 1))` |
25
+ | Soft delete | `BOOLEAN NOT NULL DEFAULT FALSE` |
26
+ | Timestamp | `TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP` |
27
+ | Financial | `NUMERIC(18,8) NOT NULL DEFAULT 0.00000000` |
28
+ | JSON | `JSON NOT NULL DEFAULT '{}'` |
29
+
30
+ NEVER use PostgreSQL ENUM — always `VARCHAR + CHECK constraint + COMMENT ON COLUMN`.
31
+
32
+ ## SQL File Content Order (strict)
33
+ 1. `-- Creating tbl_name for purpose`
34
+ 2. `DROP TABLE IF EXISTS public.tbl_name CASCADE;`
35
+ 3. `CREATE TABLE` block (id first, timestamps last)
36
+ 4. `COMMENT ON COLUMN` for every enum/flag/status column
37
+ 5. Per-table `CREATE INDEX` statements
38
+ 6. `ALTER TABLE ... OWNER TO <db_user>`
39
+ 7. `GRANT ALL ON TABLE ... TO <db_user>`
40
+ 8. Seed `INSERT` (reference/master tables only)
41
+
42
+ ## Index Strategy
43
+ Always index: every FK column; (status + is_deleted) compound; created_at DESC on log tables; email + is_deleted on user tables. Most selective column first in compound indexes.
44
+
45
+ ## create-schema.sql Maintenance
46
+ After every table operation: re-read the file → add/remove/reorder `\i` entries → write back.
47
+ ALTER files go immediately after their CREATE file. 111-indexes always last.
48
+
49
+ ## Prisma Conventions (v4.0)
50
+ - `tbl_users` → `model Users` (strip tbl_, PascalCase) + `@@map("tbl_users")`
51
+ - `id` BIGINT IDENTITY → `id BigInt @id @default(autoincrement())`
52
+ - `created_at` → `createdAt DateTime @default(now()) @map("created_at")`
53
+ - `is_deleted` → `isDeleted Boolean @default(false) @map("is_deleted")`
54
+ - FK `user_id` → `userId BigInt @map("user_id")` + relation field
55
+ - After any model addition → `npx prisma generate`
@@ -0,0 +1,77 @@
1
+ ---
2
+ applyTo: "**/*.js,**/*.ts"
3
+ ---
4
+
5
+ # codeninja — NodeJS Standards (v4.0)
6
+
7
+ ## The 2-Layer Rule (absolute)
8
+ - `route.js/ts` — HTTP only: validation, middleware, `res.json()` via sendResponse
9
+ - `<module>_model.js/ts` — DB only: queries, business logic, never `res.json()`
10
+
11
+ ## Middleware Order (never change)
12
+ ```
13
+ rateLimiter → extractLanguage → validateApiKey → [auth if protected] → decryptRequest → routeHandler
14
+ ```
15
+
16
+ ## Response Contract
17
+ ```javascript
18
+ sendResponse(req, res, 1, 'success_key', data) // success
19
+ sendResponse(req, res, 0, 'error_key', []) // error
20
+ sendResponse(req, res, -1, 'session_expired', []) // auth expired → frontend logout
21
+ ```
22
+
23
+ ## Password Hashing (v4.0 — CRITICAL)
24
+ - NEVER use `encryption.js` for passwords — reversible AES is a security vulnerability
25
+ - ALWAYS use `utilities/hashing.js`: `hashPassword(plain)` to store, `verifyPassword(plain, hash)` to check
26
+ - Import: `const { hashPassword, verifyPassword } = require('../../utilities/hashing')`
27
+ - TypeScript: `import { hashPassword, verifyPassword } from '../../utilities/hashing'`
28
+
29
+ ## ORM Branch (v4.0)
30
+ Read `context.db.orm` before generating any model:
31
+ - orm="none": parameterized SQL with `$1`, `$2` placeholders via pg/mysql2/mongoose
32
+ - orm="prisma": `prisma.tableName.operation()` — import singleton from `config/prisma`, never `new PrismaClient()`
33
+ - Prisma table access: `tbl_users` → `prisma.users` (lowercase, strip `tbl_` prefix)
34
+
35
+ ## TypeScript Support (v4.0)
36
+ Read `context.services[name].language`:
37
+ - "javascript": `.js` files, `require()`/`module.exports`, no tsconfig
38
+ - "typescript": `.ts` files, `import`/`export`, typed params, `tsconfig.json` in Wave 1
39
+
40
+ TypeScript patterns:
41
+ ```typescript
42
+ // route.ts
43
+ import { Router, Request, Response } from 'express';
44
+ router.post('/path', async (req: Request, res: Response) => { ... });
45
+ export default router;
46
+
47
+ // _model.ts
48
+ export async function functionName(request: RequestType, user_id: number, user_type: string): Promise<object> { ... }
49
+ ```
50
+
51
+ ## Localizify Rules
52
+ - ONLY `headerValidator.js/ts` and `response.js/ts` may call `t()` directly
53
+ - All other files use `sendResponse()`, `getMessage()`, or `req.t("key")`
54
+
55
+ ## Code Style
56
+ - JSDoc on every exported function (no exceptions)
57
+ - No inline `//` comments inside function bodies
58
+ - Route comment: `// POST /path — description` above each route handler
59
+ - No file-level header comments
60
+
61
+ ## .env Keys (NodeJS service)
62
+ ```
63
+ PORT=, API_KEY=, KEY=, IV=, ENCRYPTED_TRANSPORT=, SUPPORTED_LANGUAGES=,
64
+ DB_HOST=, DB_PORT=, DB_NAME=, DB_USER=, DB_PASSWORD=,
65
+ REDIS_HOST=, REDIS_PORT=,
66
+ DATABASE_URL= (Prisma only — replaces individual DB_* vars)
67
+ ```
68
+
69
+ ## Wave Generation Order
70
+ Before generating any file, read `.codeninja/tasks/generate-<name>.task.md`.
71
+
72
+ Wave 1: package.json, .env, .gitignore, README.md, config/constants, config/template, logger/logging, utilities/encryption, **utilities/hashing** (v4.0), languages/*, **tsconfig.json** (TS only, v4.0)
73
+ Wave 2: config/database OR config/prisma (v4.0 ORM branch), utilities/ioRedis, utilities/response
74
+ Wave 3: config/common, utilities/validator, utilities/notification, middleware/rateLimiter
75
+ Wave 4: middleware/headerValidator, modules/v1/<Name>/route, modules/v1/<Name>/_model, swagger_doc.json
76
+ Wave 5: modules/v1/route_manager, app.js/ts
77
+ Wave 6: Dockerfile, .dockerignore
@@ -0,0 +1,42 @@
1
+ ---
2
+ applyTo: "**/*.jsx,**/src/**"
3
+ ---
4
+
5
+ # codeninja — ReactJS Architecture Standards
6
+
7
+ ## apiClient.js — 4 Responsibilities
8
+ 1. Static headers: `api-key`, `Accept-Language`, `Content-Type: text/plain`
9
+ 2. Request interceptor: AES-encrypt body + attach encrypted token from localStorage
10
+ 3. Response interceptor (success): decrypt + parse JSON; responsecode -1 → logout
11
+ 4. Response interceptor (error): ERR_NETWORK/401 → logout + error message
12
+
13
+ ## apiHandler.js Standard
14
+ - One exported async function per backend endpoint
15
+ - No try/catch, no decryption (interceptors handle it)
16
+ - All API paths here — never in page components
17
+
18
+ ## Backend Linking Rule
19
+ ReactJS CANNOT be initialized without a linked NodeJS backend.
20
+ Inherits from linked service: `encryption_key`, `encryption_iv`, `api_key`, `port`.
21
+ NEVER ask user for these — always read from `context.services[linked_service]`.
22
+
23
+ ## Vanilla CSS Only
24
+ - Per-page: `<PageName>.module.css`
25
+ - Global: `public/assets/css/style.css`
26
+ - No Tailwind, no CSS-in-JS
27
+
28
+ ## .env Standard
29
+ ```
30
+ REACT_APP_BASE_URL=http://localhost:<linked_port>/api/v1/
31
+ REACT_APP_API_KEY=<inherited>
32
+ REACT_APP_KEY=<inherited>
33
+ REACT_APP_IV=<inherited>
34
+ ```
35
+
36
+ ## Wave Generation Order
37
+ Before generating any file, read `.codeninja/tasks/generate-react-*.task.md`.
38
+
39
+ Wave 1: package.json, .env, .gitignore, README.md, public/index.html, public/assets/css/style.css, .htaccess (root + public)
40
+ Wave 2: src/api/apiClient.js, src/api/apiHandler.js
41
+ Wave 3: src/pages/Welcome/index.jsx, src/pages/Welcome/Welcome.module.css, src/App.jsx, src/index.jsx
42
+ Wave 4: Dockerfile, nginx.conf, .dockerignore
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "codeninja",
3
- "version": "3.1.0",
4
- "description": "AI agent scaffolding system — NodeJS, ReactJS, and database projects. IDE-aware: installs Antigravity slash commands, Cursor rules, or VS Code Copilot instructions automatically.",
3
+ "version": "4.0.0",
4
+ "description": "AI agent scaffolding system — NodeJS (JS/TS), ReactJS, and database projects. Multi-agent architecture with true parallel sub-agents. Supports Prisma ORM, TypeScript, and bcrypt/argon2 password hashing. IDE-aware: Claude Code, Antigravity, Cursor, VS Code.",
5
5
  "private": false,
6
6
  "bin": {
7
7
  "codeninja": "cli.js"
@@ -0,0 +1,31 @@
1
+ ---
2
+ type: task
3
+ name: ask-hashing-library
4
+ ---
5
+
6
+ Condition: only run if `context.current_init.init_mode == "manual"` AND
7
+ `context.current_init.project_type == "nodejs"`.
8
+ In fast mode, `generate-fast-defaults` sets `hashing_library = "bcryptjs"`
9
+ automatically — skip this task.
10
+
11
+ Ask the user exactly this question:
12
+
13
+ "Which password hashing library should this service use?"
14
+
15
+ Present options:
16
+ 1. bcryptjs — pure JavaScript, no native bindings, easier to install (recommended)
17
+ 2. argon2 — stronger algorithm, requires native build tools
18
+
19
+ Wait for user selection.
20
+
21
+ Store result in: `context.current_init.hashing_library`
22
+ - Option 1 → "bcryptjs"
23
+ - Option 2 → "argon2"
24
+
25
+ Show confirmation based on selection:
26
+ - bcryptjs → "bcryptjs will be added to package.json. Passwords will be hashed
27
+ with bcrypt (SALT_ROUNDS = 12)."
28
+ - argon2 → "argon2 will be added to package.json. Passwords will be hashed
29
+ with argon2id. Native build tools (node-gyp) must be available."
30
+
31
+ Do not ask any other question in this task.
@@ -0,0 +1,26 @@
1
+ ---
2
+ type: task
3
+ name: ask-language-type
4
+ ---
5
+
6
+ # Task: ask-language-type
7
+
8
+ Condition: only run if `context.current_init.project_type == "nodejs"`.
9
+ Skip entirely for reactjs and database-only projects.
10
+
11
+ If `context.current_init.init_mode == "fast"` → skip this task,
12
+ set `context.current_init.language = "javascript"` silently, return.
13
+
14
+ Ask: "What language would you like to use for this service?"
15
+
16
+ Options:
17
+ 1. JavaScript (default) — CommonJS require/module.exports, .js files, no build step
18
+ 2. TypeScript — import/export, type annotations, .ts files, compiled to dist/
19
+
20
+ Guidance:
21
+ - JavaScript: simpler setup, runs directly with node, faster to start
22
+ - TypeScript: type safety, better IDE autocomplete, recommended for larger teams
23
+
24
+ Stores: `context.current_init.language` ("javascript" | "typescript")
25
+
26
+ Do not ask any other question in this task.