codeninja 3.2.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 +202 -85
  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 +76 -83
  18. package/ide/antigravity/.agents/workflows/codeninja-audit.md +82 -44
  19. package/ide/antigravity/.agents/workflows/codeninja-db-create.md +107 -94
  20. package/ide/antigravity/.agents/workflows/codeninja-db-drop.md +89 -67
  21. package/ide/antigravity/.agents/workflows/codeninja-db-index.md +86 -54
  22. package/ide/antigravity/.agents/workflows/codeninja-db-modify.md +126 -68
  23. package/ide/antigravity/.agents/workflows/codeninja-db-seed.md +87 -59
  24. package/ide/antigravity/.agents/workflows/codeninja-db-sync.md +77 -41
  25. package/ide/antigravity/.agents/workflows/codeninja-debug.md +35 -21
  26. package/ide/antigravity/.agents/workflows/codeninja-design.md +49 -35
  27. package/ide/antigravity/.agents/workflows/codeninja-explain.md +41 -20
  28. package/ide/antigravity/.agents/workflows/codeninja-init.md +479 -289
  29. package/ide/antigravity/.agents/workflows/codeninja-integrate-api.md +253 -136
  30. package/ide/antigravity/.agents/workflows/codeninja-modularize.md +250 -132
  31. package/ide/antigravity/.agents/workflows/codeninja-optimize.md +71 -29
  32. package/ide/antigravity/.agents/workflows/codeninja-refactor.md +50 -42
  33. package/ide/antigravity/.agents/workflows/codeninja-review.md +38 -21
  34. package/ide/antigravity/.agents/workflows/codeninja-sync.md +922 -141
  35. package/ide/antigravity/.agents/workflows/codeninja-test.md +34 -49
  36. package/ide/antigravity/.agents/workflows/codeninja-validate-page.md +449 -151
  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 +12 -13
  62. package/ide/cursor/.cursor/rules/02-mcp-and-context.mdc +47 -31
  63. package/ide/cursor/.cursor/rules/03-api-builder.mdc +32 -110
  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 +67 -382
  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 -90
  110. package/ide/cursor/.cursor/rules/05-reactjs.mdc +0 -147
  111. 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: always-loaded
3
+ scope: all-commands
4
+ loaded-for:
5
+ - all commands (always active)
4
6
  description: >
5
- MCP tool usage rules and context management protocol. Loaded on every
6
- session. Governs how every persona reads, writes, and protects context.json.
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 Management
11
+ # Skill: MCP and Context
10
12
 
11
- This skill governs all interaction with the codeninja MCP server and
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 project context | First thing on every activation |
21
- | `context_write` | Persist changes (deep-merge) | After every completed operation |
22
- | `context_clear_scratchpad` | Clear a current_* key | After writing context |
23
- | `context_check_stale` | Detect unresolved scratchpad | Step 0 of activation |
24
- | `service_scan` | Discover all services on disk | Step 2 of activation |
25
- | `migration_next_number` | Get next sequential migration number | Before creating any migration file |
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` | Surgical file insertion | Appending to route_manager.js, etc. |
30
- | `file_contains` | Check if string exists in file | Before appending to avoid duplicates |
31
- | `run_drift_check` | Compare context vs disk | During @sync workflow |
32
- | `lint_file` | Lint a generated file | After generating JS/SQL files |
33
- | `npm_check_package` | Look up npm package info | When verifying dependencies |
34
- | `npm_install` | Install a package | When adding new dependencies |
35
- | `validate_redis_connection` | Test Redis connectivity | During service init |
36
- | `validate_postgres_connection` | Test DB connectivity | During service init |
37
- | `analyze_middleware_order` | Check middleware chain | During @audit |
38
- | `analyze_encryption_library` | Verify encryption setup | During @audit |
39
- | `analyze_language_keys` | Check i18n completeness | During @audit |
40
- | `analyze_dependencies` | Scan package.json | During @audit / @sync |
41
- | `analyze_env_file` | Check .env completeness | During @audit |
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
- "features": [],
67
- "from_doc": { "project_name": "", "domain": "", "purpose": "", "features": [], "entities": [], "tech_preferences": [] },
68
- "from_sow": { "integrations": [] },
69
- "from_figma": { "screens": [] }
51
+ "has_doc": false,
52
+ "has_sow": false,
53
+ "has_figma": false
70
54
  },
71
55
  "db": {
72
- "type": "",
73
- "name": "",
74
- "host": "",
75
- "port": 0,
76
- "user": "",
77
- "schema": {}
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
- ## Scratchpad Keys (current_* pattern)
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
- | Key | Used by |
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
- After `context_write` with final results always call `context_clear_scratchpad`
101
- for the relevant key. This prevents stale data from persisting across sessions.
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
- When `context_check_stale` returns stale keys:
108
- 1. Show the user what was in progress
109
- 2. Ask: "Resume this operation or discard it?"
110
- 3. If resume → re-read the scratchpad and continue from where it left off
111
- 4. If discard call `context_clear_scratchpad` and start fresh
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
- slash_command: /codeninja:api
3
- personas: [global-orchestrator, nodejs-backend]
4
- skills: [mcp-and-context, api-builder]
5
- description: Add a new API module (route.js + model.js) to an existing NodeJS service.
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
- # /codeninja:api
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
- ## Before Running
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
- ## Execution — Full Step-by-Step
26
+ ## Step-by-Step Execution
16
27
 
17
28
  ### Phase 0 — Existing Pattern Review
18
- Before asking any questions, read existing modules in `context.services[<service_name>].modules`
19
- and scan 1–2 existing `route.js` and `_model.js` files from the service.
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
- - Auth patterns (all protected? mixed?)
25
- - Response patterns beyond standard contract
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
- **Step 1.** Ask: "Which service?" (list from `context.services`)
34
- - Store: `context.current_api.service_name`
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
- **Step 3.** Ask: "Module name?" (e.g. Products, Orders, Invoice)
44
- - Store: `context.current_api.module_name`
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
- **Step 5.** Ask: "Route path?" (e.g. /products, /products/:id)
50
- - Store: `context.current_api.route_path`
62
+ 5. Run task: `ask-route-path`
63
+ - Example: /products, /products/:id
64
+ - Stores: `context.current_api.route_path`
51
65
 
52
- **Step 6.** Ask: "Route description?" (one sentence)
53
- - Store: `context.current_api.description`
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
- **Step 7.** Ask: "Which table does this route primarily use?"
60
- - Show available tables from `context.db.schema.tables`
61
- - Store: `context.current_api.primary_table`
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 — Confirm and Generate
69
-
70
- **Step 9.** Confirm: "Generate [METHOD] [path] in [service]/modules/[version]/[Module]? (yes/no)"
71
-
72
- **Step 10.** Delegate to nodejs-agent generate ALL files simultaneously:
73
-
74
- - `modules/<version>/<ModuleName>/route.js`
75
- - Full validation schema using `validatorjs`
76
- - All middleware applied in correct order
77
- - Calls model function, returns via `sendResponse`
78
- - JSDoc on every handler
79
-
80
- - `modules/<version>/<ModuleName>/<module>_model.js`
81
- - Parameterized queries onlyno string concatenation
82
- - References actual column names from `context.db.schema`
83
- - Returns exactly `{ responsecode, responsemsg, responsedata }`
84
- - No `res.json()` anywhere in this file
85
-
86
- - Append to `modules/<version>/route_manager.js`
87
- - Use `file_insert_after` MCP tool — NEVER rewrite this file
88
- - Surgical insert of `router.use('/<path>', require('./<Module>/route'))` only
89
- - Use `file_contains` first to avoid duplicate registration
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 filesurgical 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
- slash_command: /codeninja:audit
3
- personas: [global-orchestrator, nodejs-backend]
4
- skills: [mcp-and-context, api-builder, code-intelligence]
5
- description: Deep security and quality review of an existing NodeJS service.
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
- # /codeninja:audit
32
+ ## Step-by-Step Execution
9
33
 
10
- ## Before Running
11
- 1. Call `context_read`
12
- 2. Call `context_check_stale`
34
+ 1. Run task: `ask-target-service`
13
35
 
14
- ## Execution Full Step-by-Step
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
- **Step 1.** Ask: "Which service to audit?" (list from `context.services`)
39
+ 2. Delegate to relevant agent(s) based on service type.
17
40
 
18
- **Step 2.** Delegate to nodejs-agent. Run all checks:
41
+ 3. Agent checks:
19
42
 
20
43
  ### Security Checks
21
- - [ ] API key validation middleware on ALL routes?
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 only)?
46
+ - [ ] SQL injection prevention (parameterized queries)?
24
47
  - [ ] Sensitive values only from env vars (no hardcoded keys/passwords)?
25
48
  - [ ] `.env` in `.gitignore`?
26
- - [ ] Real AES-256-CBC encryption (not base64)?
27
- - [ ] `utilities/encryption.js` is the ONLY file importing crypto-js or cryptlib?
28
- - [ ] `res.json()` never called directly in route.js or model files?
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 notification.js or template.js?
31
- - [ ] Firebase service account file in `pem/` and in `.gitignore`?
32
- - [ ] `GLOBALS` object frozen using `Object.freeze()`?
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
- - [ ] Only services called from controllers (no DB queries in controllers)?
36
- - [ ] Models contain only DB queries and business logic?
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 `checkValidationRules` from `utilities/validator.js`?
39
- - [ ] No separate `_validator.js` files per module?
40
- - [ ] `rateLimiter` is FIRST middleware in `route_manager.js`?
41
- - [ ] `extractLanguage` runs BEFORE `validateApiKey` in `route_manager.js`?
42
- - [ ] `decryptRequest` is LAST middleware in the chain?
43
- - [ ] No route handlers defined directly in `route_manager.js`?
44
- - [ ] `asyncHandler` wraps every middleware in `route_manager.js`?
45
- - [ ] All model functions return exactly `{ responsecode, responsemsg, responsedata }`?
46
- - [ ] No `req/res` objects in any model file?
47
- - [ ] Passwords encrypted via `utilities/encryption.js` before storage?
48
- - [ ] Session tokens generated only via `common.generateSessionCode()`?
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[<n>].port`?
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 `sendResponse` calls exist in `languages/en.js`?
57
- - [ ] All language files have the same keys as `en.js`?
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 exactly 32 chars in context.services?
60
- - [ ] All encryption IVs exactly 16 chars in context.services?
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 `router.use()` lines in route_manager.js have a corresponding entry in context.services modules?
66
- - [ ] All context.services modules have a corresponding `router.use()` in route_manager.js?
67
- - [ ] All swagger_doc.json paths have a corresponding entry in context.api_routes?
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
- **Step 3.** Present audit report:
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
- **Step 4.** Ask: "Auto-fix critical issues? (yes/no)"
81
- If yes → delegate to nodejs-agent for fixes → call `context_write` after.
118
+ 5. Ask: "Auto-fix critical issues? (yes/no)"
119
+ 6. If yes → delegate to relevant agent for fixes → run task: `write-context`